Styling a QAbstractItemView item
I am attempting to style the items in QCompleter's dropdown via .qss
In my .qss file styles I declare in
work however styles in
are completely ignored. In particular I am trying to increase spacing between items, does anybody know how to do that?
Re: Styling a QAbstractItemView item
Ok I came back to this problem and found the problem & solution! So I thought I would share because I came across other people posting similar problems but never anybody posting a solution.
QCompleter sets a custom QAbstractItemDelegate on it's model and unfortunately this custom item delegate does not inherit QStyledItemDelegate but simply QItemDelegate (and then overrides the paintmethod to show the selected state).
So in order to use the stylesheet ::item subcontrol with QCompleter you need to do something like this
Code:
mCompleterItemDelegate = new QStyledItemDelegate(this);
...
mCompleter.setModel(someitemmodel);
mCompleter.popup()->setItemDelegate(mCompleterItemDelegate); //Must be set after every time the model is set
Now the items in the QCompleter popup list can be styled via standard stylesheet syntax
Code:
margin: 2px;
}
background: orange;
}
Re: Styling a QAbstractItemView item
Many thanks for sharing the solution!
It's a shame that isn't possible at the moment to make it work from Designer's .ui forms. Having to set the StyledItemDelegate for every QComboBox(in my case) right after calling the form setupUi() method is quite painful...but better than nothing :).