Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to customize QComboBox's layout
lucadanieli last edited by
I don't find the answer in internet. Is there any chance to customize QComboBox in order to make it fit properly the surrounding style of the program? I mean changing the color of the Bar, and not of the popup area, for example. And the shape of the menu, the style of the rows and so on.
The more the opportunities, the better it is.
Jeroentjehome last edited by
If you need basic colour settings changed, use the stylesheet way.
If you need advanced changes, you are looking at subclassing the QComboBox and implement the paintEvent etc
thEClaw last edited by
You can substitute your completely customized view via "QComboBox::setView":http://qt-project.org/doc/qt-5/qcombobox.html#setView or even take full control of the item delegate via "QComboBox::setItemDelegate":http://qt-project.org/doc/qt-5/qcombobox.html#setItemDelegate - the latter one is used to draw the contents of the list that pops up when you use the combobox.
If you just want the combobox to fit its surroundings, maybe you only need to set its parent properly. Widgets normally inherit style and palette from their parents. And if the parent was using a style sheet, you could make use of that, too (depending on the style sheet it might not be completely straight forward, however).
The "QComboBox::paintEvent":http://qt-project.org/doc/qt-5/qcombobox.html#paintEvent of course would give you complete control of the combo box-painting itself (I guess not of the popup-list, though - but that would be covered by the formerly mentioned item delegate).