如何在QComboBox中修改单个项目的样式?

时间:2013-05-13 12:36:37

标签: qt

鉴于QComboBox小部件,我可以轻松更改下拉列表的样式。例如,此样式表为下拉列表添加绿色边框:

QComboBox QAbstractItemView { border: 5px solid green; }

enter image description here

但是,如果我尝试更改单个项目的样式,它根本不起作用:

QComboBox QAbstractItemView::item { border: 5px solid green; }

enter image description here

可以在QComboBox中更改单个列表项的样式,还是不支持?

1 个答案:

答案 0 :(得分:1)

是的,你可以做到。您需要的只是使用QAbstractItemDelegate。要使用它,只需调用QComboBox :: setItemDelegate()