• 7256阅读
  • 5回复

如何设置QTable 某一行的背景色,或者如何设置某个单元格的背景色? [复制链接]

上一主题 下一主题
离线jixiaodong
 
只看楼主 正序阅读 楼主  发表于: 2008-10-19
— 本帖被 XChinux 执行加亮操作(2008-11-02) —
如题,在线的前辈帮忙啊 ,急用
离线jixiaodong
只看该作者 5楼 发表于: 2008-10-22
请问lanfe:
  你在帖子中说“QTable头文件中定义 
virtual void paintCell( QPainter *p, int row, int col,const QRect &cr, bool selected, const QColorGroup &cg );
你可以继承QTable,然后重写paintCell函数
QColorGroup g1( cg );
if (selected==false)
    g1.setColor( QColorGroup::Base, QColor(210,230,230) );
QTable::paintCell(p, row, col, cr, selected, g1);”


我的问题是:我可以直接调用该函数吗?
若可以,调用virtual void paintCell( QPainter *p, int row, int col,const QRect &cr, bool selected, const QColorGroup &cg )时cr该传递什么值?


注:提出第一个问题的原因:paintCell好像是有QTable中的( int row, int col, QTableItem * item )间接调用的,因为void QTable::setItem ( int row, int col, QTableItem * item ) [virtual] 函数的说明文档是
Inserts the table item item into the table at row row, column col, and repaints the cell. If a table item already exists in this cell it is deleted and replaced with item. The table takes ownership of the table item.
If you don't use QTableItems you may need to reimplement this function: see the notes on large tables.
因此,我认为我们作为用户,不用直接调用paintCell函数
离线jixiaodong
只看该作者 4楼 发表于: 2008-10-20
好的,我试试各位大侠的思路。有问题再回来问
离线chaoscxm
只看该作者 3楼 发表于: 2008-10-20
QTableView.model().setData( row, col, value, role)
其中value为颜色,role指定为背景色,具体请参考doc
帖子签名(将在每个帖子下方显示)
离线lanfe
只看该作者 2楼 发表于: 2008-10-20
QTable头文件中定义 
virtual void paintCell( QPainter *p, int row, int col,const QRect &cr, bool selected, const QColorGroup &cg );


你可以继承QTable,然后重写paintCell函数
QColorGroup g1( cg );
if (selected==false)
    g1.setColor( QColorGroup::Base, QColor(210,230,230) );
QTable::paintCell(p, row, col, cr, selected, g1);
离线lazybone
只看该作者 1楼 发表于: 2008-10-20
CSS 吧
快速回复
限100 字节
 
上一个 下一个