关于Qt 5.3中“comBox->addItem(); ”函数

wuleeemail 2015-03-04 02:20:42
就是想实现组合框下拉菜单选择不同颜色显示的功能,这当中使用了comBox->addItem();函数,代码如下:
02. QComboBox *comBox;
03. QPixmap pix(16,16); //创建绘图设备
04. QPainter painter(&pix);//创建一个画笔
05. painter.fillRect(0,0,16,16,Qt::black);
06. comBox->addItem(QIcon(pix),tr("黑色"),Qt::black);
07. //红色
08. painter.fillRect(0,0,16,16,Qt::red);
09. comBox->addItem(QIcon(pix),tr("红色"),Qt::red);
但是在编译的时候报错:1)C:\Qt\Qt5.3.0\5.3\mingw482_32\include\QtCore\qvariant.h:481: error: 'QVariant::QVariant(Qt::GlobalColor)' is private
QVariant(Qt::GlobalColor) Q_DECL_EQ_DELETE;

2)D:\User\paint\mainwindow.cpp:192: error: within this context
comboBox->addItem(QIcon(pix),tr("黑色"),Qt::black);
请问这是为何?这段代码应该是很成熟的,不应该再会出现这种错误。
...全文
986 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lynnhua_ 2015-03-04
  • 打赏
  • 举报
回复
QComboBox设置代理Item可以帮你实现Item颜色显示的问题!
  • 打赏
  • 举报
回复
// These constructors don't create QVariants of the type associcated // with the enum, as expected, but they would create a QVariant of // type int with the value of the enum value. // Use QVariant v = QColor(Qt::red) instead of QVariant v = Qt::red for // example.
  • 打赏
  • 举报
回复
加个强制转换吧,出于某种原因禁止了

16,211

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧