PDA

View Full Version : Styling QCombobox



WereWind
16th June 2016, 13:58
I have a rather simple-looking problem that stumbled me for quite some time.
I have a QtWidgets app with a QComboBox, It's a standart combobox but with a tickmark next to a selected item. This tick mark is caused by this bit of style sheet

QComboBox
{
background-color: red
}

QComboBox:on
{
background-color: green
}

If both these items are missing from the stylesheet, there is no tick, if any one - the tick mark is here.

Now I want to make the items of the combobox a bit larger. Some snoopind revealed that the most reliable way for doind so is applying a QStyledItemDelegate with its sizeHint overriden. The function looks like this

QSize CComboBoxPopupItemDelegate::sizeHint(const QStyleOptionViewItem&,
const QModelIndex &) const {
return QSize(200, 60);
}

and installation went like this

language_selector_->view()->setItemDelegate(new CComboBoxPopupItemDelegate(this));


The items indeed grew to the desired size but the tick mark was gone. Also the colors were wrong - instead of red and green it's the deafult window colors
Is there a way to both increase the size of the items in the popup and keep the tickmark?

My OS in Ubuntu if it's of any relevance.