Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Qt5.6: How to disable the QComboBox's Up/Down arrows and show all items?

    General and Desktop
    qcombobox
    2
    2
    3298
    Loading More Posts
    • 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.
    • cgripeos
      cgripeos last edited by cgripeos

      Hello,

      I'm creating a QComboBox with three items in it.

      When clicking on the combo box,

      In Qt4.8, they all show up at once in one vertical list.

      In Qt5.6, two items show and the third is hidden by the "down" arrow. The QComboBox only provides room to show two out of the three items. The user needs to mouse-scroll down or click the down arrow to show the third item.

      Is there a way to disable the up/down arrows and show the whole list at once?

      I use a a QStyledItemDelegate for the QComboBox::setItemDelegate().

      The code is as follows:

      cb = new QComboBox(this);
      cb->setItemDelegate( new QStyledItemDelegate);
      cb->setMaxCount(3);
      cb->setSizeAdjustPolicy(QComboBox::AdjustToContents);
      cb->setMaxVisibleItems(10);

      If I add more items, the problem persists, even if I increase the QComboBox::setMaxCount().

      If I use QItemDelegate instead of QStyledItemDelegate, all items are shown just fine, but I'd like to make this work with QStyledItemDelegate.

      Thanks in advance for any help!

      cg

      1 Reply Last reply Reply Quote 0
      • R
        rzhurov last edited by

        Solution that works for me is to call unpolish and polish on combo box:

        auto cb = new QComboBox(this);
        cb->setItemDelegate( new QStyledItemDelegate);
        style()->unpolish(cb);
        style()->polish(cb);
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post