• 5581阅读
  • 2回复

QTableView的问题 [复制链接]

上一主题 下一主题
离线zlyrtn
 

只看楼主 倒序阅读 楼主  发表于: 2011-04-02
请问在QT4中我用QTableView 和QSqlTableModel操作数据,我想改变tableview某行的背景色应该怎么做?
离线XChinux

只看该作者 1楼 发表于: 2011-04-03
从QSqlTableModel派生一个类,在该类中实现一下 data()方法。楼主在论坛里查找一下data()相关帖子。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线hhu_zhou

只看该作者 2楼 发表于: 2011-04-27
你需要在tableView建立一个委托,然后重写void paint ( QPainter *painter,    const QStyleOptionViewItem &option,    const QModelIndex &index ) const;接口。
在接口中加入如下代码
            QStyleOptionViewItem myOption = option;
            QRect rect = option.rect;
            QPoint x1 = rect.bottomLeft();
            QPoint x2 = rect.bottomRight();
            QPoint y1 = rect.topRight();

            QBrush brush ( Qt::red );
            painter->fillRect ( rect.left(), rect.top(), rect.width(), rect.height(), brush );
            QItemDelegate::drawBackground ( painter, option, index );
快速回复
限100 字节
 
上一个 下一个