QComboBox: Bold Font for selected item in drop down list
-
I am trying to get the text for a selected item as BOLD in the QComboBox drop down list. I have looked at all the forums and tried stylesheets, palletes, and setItemData but nothing seems to work.
Here is a snippet of my QComboBox setup. Any any help would be appreciated:
QStringList strList; m_pModel = new QStringListModel(strList, this); m_pSortFilterProxyModel = new QSortFilterProxyModel(this); m_pSortFilterProxyModel->setSourceModel(m_pModel); m_pSortFilterProxyModel->setFilterCaseSensitivity(Qt::CaseSensitive); m_pComboBox->setModel(m_pGatewaySortFilterProxyModel); m_pComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); m_pComboBox->setInsertPolicy(QComboBox::NoInsert); m_pComboBox->setEnabled(true);
-
-
@JonB said in QComboBox: Bold Font for selected item in drop down list:
Are you sure one can have bold text in a combo box?
At least in the dropdown box, yes. It's a QStandardItemModel so:
QStandardItemModel *m = qobject_cast<QStandardItemModel *>(cbx->model()); QStandardItem *item = m ? m->item(row) : nullptr; if (item) { auto f = item->font(); f.setBold(true); item->setFont(f); }
-
@Christian-Ehrlicher
But isn't aQComboBox
rendered as the native windowing system control? How do you know whether, say, GNOME or Unity can boldize an item in a dropdown? -
@JonB No, it's not - it's more or less an itemview: https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qcombobox.cpp.html#_ZN25QComboBoxPrivateContainer10paintEventEP11QPaintEvent
-
@Christian-Ehrlicher
So are you saying theQComboBox
is not whatever the native windowing system's "combobox" control is? Instead it's drawn via Qt code? I assumed under Windows it was the Windows combobox, etc. -
At least it looks like, but did not look at the style plugins though.