PDA

View Full Version : QComboBox hide top item from list



karankumar1609
21st May 2013, 09:33
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?

rawfool
21st May 2013, 10:00
Assuming that you want to remove/hide "Show" on some event, you have to do the following -


removeItem(int index); // for removing
insertItem(int index, QString item);// for inserting back
//index is 0 for first item

karankumar1609
21st May 2013, 10:15
Thanks for your quick reply but i have done it via



QMenu* showToolMenu = new QMenu(ui->button_Show);
showToolMenu->addAction("View", this, SLOT(on_button_file_Download_clicked()));
showToolMenu->addAction("Download", this, SLOT(on_button_file_View_clicked()));
ui->button_Show->setMenu(showToolMenu);


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.

rawfool
21st May 2013, 10:19
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.

lanz
21st May 2013, 10:45
If you want get rid of the arrow (assuming you have QToolButton) you can call:

ui->button_Show->setPopupMode (QToolButton::InstantPopup)
Although be aware that

In this mode, the button's own action is not triggered.
http://qt-project.org/doc/qt-4.8/qtoolbutton.html#popupMode-prop

karankumar1609
21st May 2013, 11:01
ui->button_Show->setPopupMode (QToolButton::InstantPopup)


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


QPushButton#evilButton::menu-indicator {
image: none;
}


above code works for me