用不同的颜色填充QTreeView中的单元格,用不同的颜色填充QDiagCrossPattern
Fill cell in a QTreeView with a different color and QDiagCrossPattern with a different color
我正在使用QTreeView,其中我希望特定单元格具有背景色,例如蓝色,并具有带有灰色的Qt::D iagCrossPattern。最好在 Model::d ata 而不是 paint 中使用此实现。有没有办法通过模型::D ata本身中的Qt::BackgroundRole来实现这一点?我试过这样做:
Model::data(const QModelIndex &index, int role) const
{
case Qt::BackgroundRole:
{
QColor backgroundcolor = Qt::blue;
return QBrush(backgroundcolor, Qt::DiagCrossPattern);
}
}
但这可以使背景颜色保持透明,并且对角图案线为蓝色,这不是必需的。
您可以创建一个纹理(例如QPixamp
)并在QBrush
中使用它
参见QBrush(const QPixmap&)
对于纹理,您可以加载图像或使用QPainter
创建图像
QPixmap pixmap(16, 16);
pixmap.fill(QColor(0, 0, 255));
QPainter painter(&pixmap);
painter.fillRect(pixmap.rect(), QBrush(QColor(128, 128, 128), Qt::DiagCrossPattern));
相关文章:
- 在c++中用vector填充一个简单的动态数组
- 如何使用用户输入在C++中正确填充2D数组
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 如何找到大小'x'数组是否完全填充,在C++?
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 通过for循环使用用户输入填充列表
- 如何在内核C++中使用1920x1080x16M图形或类似的16M颜色?(VGA)
- 如何在24位SDL_Surface上设置像素的颜色
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 如何从SDL_Surface获取特定像素的颜色
- 如何正确填充在堆上分配的二维数组?
- 如何用某种颜色填充QGraphicsRectItem
- 用不同的颜色填充QTreeView中的单元格,用不同的颜色填充QDiagCrossPattern
- 简单的颜色填充QCon中的QT
- 4路泛光填充功能,无需通过起始颜色
- 如何在 cocos2d-x 中用颜色绘制圆形填充
- 如何用3种随机颜色的梯度填充图像
- C++使用 FLTK 填充形状中的颜色不适用于圆圈
- 如何画一个椭圆填充一定的颜色
- 在OpenGL中用一些颜色填充布里森汉姆圆