Results 1 to 6 of 6

Thread: QComboBox hide top item from list

  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QComboBox hide top item from list

    Hello,

    I have a problem with Qt Combobox.
    I have added three item in comboBox : "Show" , "View", "Download"
    Here "Show" is the permanently visible item for combobox even if i click on "View" or "Download".
    But the problem is whenever popup of combobox comes it shows all three items i dont know how to hide the "Show" option in my list.
    Please any idea about that?

  2. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QComboBox hide top item from list

    Assuming that you want to remove/hide "Show" on some event, you have to do the following -

    Qt Code:
    1. removeItem(int index); // for removing
    2. insertItem(int index, QString item);// for inserting back
    3. //index is 0 for first item
    To copy to clipboard, switch view to plain text mode 
    Last edited by rawfool; 21st May 2013 at 09:04.

  3. The following user says thank you to rawfool for this useful post:

    karankumar1609 (21st May 2013)

  4. #3
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QComboBox hide top item from list

    Thanks for your quick reply but i have done it via

    Qt Code:
    1. QMenu* showToolMenu = new QMenu(ui->button_Show);
    2. showToolMenu->addAction("View", this, SLOT(on_button_file_Download_clicked()));
    3. showToolMenu->addAction("Download", this, SLOT(on_button_file_View_clicked()));
    4. ui->button_Show->setMenu(showToolMenu);
    To copy to clipboard, switch view to plain text mode 

    but now i got stucked in a problem.
    when i run this code, there is an arrow icon visible on button.
    please let me know how to remove arrow icon from button.

  5. #4
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QComboBox hide top item from list

    That arrow suggests that the button has a menu, nothing else. It's an indication to the user that on press of the button, a pop-up menu will be showed.

  6. #5
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox hide top item from list

    If you want get rid of the arrow (assuming you have QToolButton) you can call:
    Qt Code:
    1. ui->button_Show->setPopupMode (QToolButton::InstantPopup)
    To copy to clipboard, switch view to plain text mode 
    Although be aware that
    In this mode, the button's own action is not triggered.
    http://qt-project.org/doc/qt-4.8/qto...popupMode-prop

  7. #6
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QComboBox hide top item from list

    Qt Code:
    1. ui->button_Show->setPopupMode (QToolButton::InstantPopup)
    To copy to clipboard, switch view to plain text mode 

    i have used the above code but still i am unable to remove that arrow icon.

    i know that arrow indicates that button has a menu, n=but i want to remove that icon.


    Added after 8 minutes:


    ahhhhh
    i just missd that
    Qt Code:
    1. QPushButton#evilButton::menu-indicator {
    2. image: none;
    3. }
    To copy to clipboard, switch view to plain text mode 

    above code works for me
    Last edited by karankumar1609; 21st May 2013 at 10:01.

Similar Threads

  1. QcomboBox hide the drop down arrow
    By Mrdata in forum Newbie
    Replies: 6
    Last Post: 5th October 2018, 03:05
  2. Replies: 4
    Last Post: 14th June 2012, 23:33
  3. Replies: 2
    Last Post: 19th March 2012, 14:04
  4. Show QComboBox list while editing
    By radix07 in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2011, 16:52
  5. Replies: 0
    Last Post: 10th March 2011, 11:44

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.