Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox: Bold Font for selected item in drop down list

QComboBox: Bold Font for selected item in drop down list

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anshah
    wrote on last edited by
    #1

    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);
    
    JonBJ 1 Reply Last reply
    0
    • A anshah

      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);
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @anshah
      Nothing in your code has anything to do with any text, selection, or boldness....

      Are you sure one can have bold text in a combo box? I'm not saying you can't, just I don't know if it uses a native control which does not allow it?

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by Christian Ehrlicher
        #3

        @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);
        }
        

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        JonBJ 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          @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);
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Christian-Ehrlicher
          But isn't a QComboBox rendered as the native windowing system control? How do you know whether, say, GNOME or Unity can boldize an item in a dropdown?

          Christian EhrlicherC 1 Reply Last reply
          0
          • JonBJ JonB

            @Christian-Ehrlicher
            But isn't a QComboBox rendered as the native windowing system control? How do you know whether, say, GNOME or Unity can boldize an item in a dropdown?

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            JonBJ 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Christian-Ehrlicher
              So are you saying the QComboBox 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.

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                At least it looks like, but did not look at the style plugins though.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved