在mac和linux的QComboBox中交替行颜色
alternating row colors in a QComboBox in mac and linux
我想替换QComboBox的颜色。在Windows中,我使用view(). setalternatingrowcolors (true)函数没有问题。在Linux和Mac中,这似乎是不可能的。我也尝试使用样式表(见下面的代码),但我有相同类型的结果(所有行具有相同的背景颜色)。你能解释一下我的错误是什么吗?
#include <QtGui/QApplication>
#include <QComboBox>
#include <QAbstractItemView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setStyleSheet("QComboBox QAbstractItemView{qproperty-alternatingRowColors: true;alternate-background-color: blue;background: red;}");
QComboBox b;
b.addItem("MM_NONE");
b.addItem("MM_VERT");
b.addItem("MM_FACE");
b.addItem("MM_EDGE");
bool tt = false;
tt = b.view()->alternatingRowColors();
b.show();
return a.exec();
}
至少在我的盒子上,QPalette::Base
和QPalette::AlternateBase
似乎是相同的颜色:)将QPalette::AlternateBase
更改为其他颜色使此代码工作良好:
#include <QtGui/QApplication>
#include <QComboBox>
#include <QAbstractItemView>
#include <QPalette>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QComboBox b;
b.view()->setAlternatingRowColors(true);
QPalette p = b.palette();
p.setColor(QPalette::AlternateBase, Qt::red);
b.setPalette(p);
b.addItem("MM_NONE");
b.addItem("MM_VERT");
b.addItem("MM_FACE");
b.addItem("MM_EDGE");
b.show();
return a.exec();
}
相关文章:
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 如何在内核C++中使用1920x1080x16M图形或类似的16M颜色?(VGA)
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 在QComboBox或QListWidget中设置所选元素的样式文本?
- 列表视图更改选择颜色
- GtkTreeView 交替行颜色
- 如何在QGridLayout中获取QComboBox的当前文本?
- dx11 渲染到纹理仅显示透明颜色
- 使用 OpenGL 4.5 更改所选顶点的颜色
- 为什么我的 LEGACY OPENGL 颜色反转了?
- 如何更改QComboBox项目的高度大小?
- 双击更改 mfc 中列表控件中的行的颜色
- 更改 QT 中按钮的颜色
- 当我使用CHAR_INFO结构时,控制台会无缘无故地改变颜色
- 列表视图项的替代颜色
- GLSL 将 uint 转换为浮点颜色
- std::带有颜色和标题的 clog 包装器无法正确打印整数
- Vec3b:r/g/b 颜色的最大值为 254,而不是 255
- 在mac和linux的QComboBox中交替行颜色