有没有办法可以增加 QComboBox 控件中列出的项目的高度?
我尝试按照此处的建议进行操作 in QTDevNet forums但没有运气
QComboBox QAbstractItemView::item {margin-top: 3px;}
我也试过这个,仍然没有结果。
QComboBox QAbstractItemView::item {min-height: 20px;}
是否有可能在样式表级别实现这一点?
最佳答案
你的样式表似乎是正确的,所以我试了一下。看来问题类似于 this one on Qt centre :
QCompleter
sets a customQAbstractItemDelegate
on its model and unfortunately this custom item delegate does not inheritQStyledItemDelegate
but simplyQItemDelegate
(and then overrides thepaint
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/