qt - QComboBox AbstractItemView::item

标签 qt qt4 qcombobox qtstylesheets

有没有办法可以增加 QComboBox 控件中列出的项目的高度?

我尝试按照此处的建议进行操作 in QTDevNet forums但没有运气

QComboBox QAbstractItemView::item {margin-top: 3px;}

我也试过这个,仍然没有结果。
QComboBox QAbstractItemView::item {min-height: 20px;}

是否有可能在样式表级别实现这一点?

最佳答案

你的样式表似乎是正确的,所以我试了一下。看来问题类似于 this one on Qt centre :

QCompleter sets a custom QAbstractItemDelegate on its model and unfortunately this custom item delegate does not inherit QStyledItemDelegate but simply QItemDelegate (and then overrides the paint method to show the selected state).



如果您将默认委托(delegate)替换为 QStyledItemDelegate ,您的样式表应该可以工作:
QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();
combo->setItemDelegate(itemDelegate);

重要提示:如果您更改模型,那么这将重置 View 的委托(delegate),因此需要在调用 setModel() 之后调用上述方法。 .

关于qt - QComboBox AbstractItemView::item,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13308341/

相关文章:

c++ - Qt:动画 QPixmap

ios - QT Creator iOS 错误 : The settings in the Devices window of Xcode might be incorrect

linux - super 终端使用的TCP/IP通信协议(protocol)?

qt - QComboBox 的初始项目是否可以显示比项目列表中更短的文本项目?

c++ - 有没有办法防止 header 定义的 c++ 函数被视为内联

qt - 使用中继器填​​充 GridLayout

c++ - QT 自定义 TreeView

c++ - 如何在 Linux 上使用 QProcessEnvironment 设置代理地址?

qt - 如何为当前项目制作 QCombobox 绘画项目委托(delegate)? (Qt 4)

c++ - 将 QcheckBoxes 动态添加到 QScrollArea?