Qt tableView 如何单独设置某一列的背景颜色,如何设置某列的属性为NoSelection 5
其实就是想实现的功能和在Windows里面以详细列表查看文件一样,点击列标题后该列的背景色都变,另外,修改日期和属性列式不能被选中的...
其实就是想实现的功能和在Windows里面以详细列表查看文件一样,点击列标题后该列的背景色都变,另外,修改日期和属性列式不能被选中的
展开
展开全部
必须重写QItemDelegate的paint方法。
xxxx.h
class Delegate :publicQItemDelegate
{
Q_OBJECT
public:
Delegate(QWidget*parent =0):QItemDelegate(parent){}
void paint(QPainter*painter, constQStyleOptionViewItem&option,
constQModelIndex&index)const;
};
xxxx.cpp
table->setItemDelegate(new Delegate);
void Delegate::paint(QPainter*painter, constQStyleOptionViewItem&option,
constQModelIndex&index)const
{
if(index.column()== 2)
painter->fillRect(option.rect, option.palette.highlight());
QItemDelegate::paint(painter, option, index);
}
xxxx.h
class Delegate :publicQItemDelegate
{
Q_OBJECT
public:
Delegate(QWidget*parent =0):QItemDelegate(parent){}
void paint(QPainter*painter, constQStyleOptionViewItem&option,
constQModelIndex&index)const;
};
xxxx.cpp
table->setItemDelegate(new Delegate);
void Delegate::paint(QPainter*painter, constQStyleOptionViewItem&option,
constQModelIndex&index)const
{
if(index.column()== 2)
painter->fillRect(option.rect, option.palette.highlight());
QItemDelegate::paint(painter, option, index);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询