隐藏 QComboBox 标签中的图标 [英] Hide Icon from the label of QComboBox

查看:250
本文介绍了隐藏 QComboBox 标签中的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个 QComboBox,它包含 QIconQString,如下所示:

I am trying to implement a QComboBox, which holds QIcon and QString, like this:

QComboBox.addItem(icon, label);

我希望图标在下拉列表中可见,但在工具栏中不可见.选择项目后,只有字符串应该可见.

I want the icons to be visible in the drop-down list, but not in the toolbar. Only the string should be visible after item selection.

有没有简单的方法可以做到这一点?

Is there an easy way to do this?

推荐答案

最好的方法是设置一个委托并自己绘制项目.然后您可以选择何时或不绘制图标(decorationRole),您可以选择不为当前索引的索引绘制图标.我可以找到一个关于如何在组合框上使用委托的快速示例:http://programmingexamples.net/wiki/Qt/Delegates/ComboBoxDelegate

The best way is to set a delegate and to draw the items yourself. Then you can choose when or not to draw the icon ( decorationRole ), you can choose not to draw the icon for the index which is the current index. I could find a quick example on how to use a delegate on combobox: http://programmingexamples.net/wiki/Qt/Delegates/ComboBoxDelegate

但恐怕这不是最简单的方法.祝你好运!

But I am afraid it is not the most easist of the ways. Good luck!

这篇关于隐藏 QComboBox 标签中的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆