Questions tagged [qcombobox]

QComboBox is a Qt class that implements a standard combo-box, which is a list of elements that can contract to occupy less screen space, and expand to show all of the options.

In it's "closed" view, the QComboBox displays the current selection. It can also pop-up to show all of the choices, and can as well be user-editable.

QComboBox can be operated dynamically to insert (with insertItem() and insertItems() functions), remove (removeItem()), and clear (clear()) items.

One can also get the current item's index and text.

An example of creating a QComboBox and showing it will look like this:

//creating the combobox with no parent, so it appears in a new window.
QComboBox * b = new QComboBox();
//Inserting 3 elements into it. 
b->insertItems(0, QStringList() << "item1" << "item2" << "item3");
//Showing the ComboBox.
b->show();

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

727 questions
3
votes
1 answer

PyQt: How to set ComboBox current item Wihtout knowing Item's Index Number

Created myComboBox with: myComboBox = QtGui.QComboBox() Populated it with three items: myItemsList = ['item01', 'item02', 'item03'] for item in myItemsList: myComboBox.addItem(item) Now I want to set a comboBox to a second item knowing only…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
3
votes
1 answer

PyQt Different colors in a single row in a combobox

I'm developing a UI using PyQt where a single item in my Qcombobox can have two or three words separated by commas. So for eg item 1 can be 'Text1, Text2, Text3' and item 2 will be 'Text4, Text5'. What I want to do is give multiple background colors…
floyd1510
  • 391
  • 1
  • 6
  • 14
3
votes
0 answers

spacing between item in qlistview creates scrollbar

Im trying to set spacing between the items in QCombobox. for the spacing i used the 1.listview of the combobox and used setSpacing(2) for setting the spaces between the item. in customCombobox class QListView * listView = new…
Wagmare
  • 1,354
  • 1
  • 24
  • 58
3
votes
1 answer

how to add stylesheet for separator in QCombobox

i added two items in a qcombobox with a separator addItem("New"); addItem("Delete"); insertSeparator(2); in order to highlight the selection of item with different style i used QLIstView for the QComboBox view with the stylesheet as QListView *…
Wagmare
  • 1,354
  • 1
  • 24
  • 58
3
votes
1 answer

How to catch QComboBox popup close event

A am using QComboBox derived class to show my items. My combo box is read only. But how can I catch the event when popup view of combo box closes?.For example, when user clicks a mouse button somewhere out of my combo box? Thank you very much in…
pau
  • 352
  • 3
  • 14
3
votes
1 answer

Not able to hide Choice-Indicator of the QComboBox

programmer When I set the background-color of the list view belonging to the QComboBox (per QSS), then this QComboBox will no more use the built-in-opticel-look-and feel. Instaed I have to specify all optical settings also per…
CWIMMER
  • 161
  • 2
  • 4
3
votes
1 answer

Search QString in QComboBox

How can I find a QString in a QComboBox? I want to get the index of the element in the combobox that's corresponding to my string. Is there a native method? Thanks in advance.
Marco Carletti
  • 318
  • 2
  • 5
  • 16
2
votes
2 answers

How to show an item with a given index number in QComboBox?

I have added some items in a QComboBox and now I am trying to show an item on the QComboBox with given index. For example: In my QComboBox, I have three items; firstItem, secondItem, thirdItem, when I get an index number two, I want to see…
mehmetozer
  • 848
  • 6
  • 14
  • 30
2
votes
2 answers

How do i select at item in a QTreeView that is inside a QComboBox

I have a QtreeView as the view in a QComboBox. In my app the root items are category labels and are not to be selected. When i create the view i would like to pre select one of the child items (the first root item is selected by default), but i…
tom
  • 53
  • 1
  • 5
2
votes
2 answers

Qt ComboBox->addItem() Integer to Qstring conversion error?

I am really new to Qt and I have a little question for you. I am trying to work on ComboBox and when I add items to a combobox an integer like; combobox->addItem(class.value); // class.value is an integer It just adds a symbol to the combobox (*,…
mehmetozer
  • 848
  • 6
  • 14
  • 30
2
votes
1 answer

How to set icon of the line edit in a QCombobox widget without inserting the item into the list?

I want to set the icon on the left side of the QCombobox widget. I know I can insert a item first and then set the icon of the inserted item and then select this newly inserted item. However, I would like to do that without inserting a new item into…
Stephen Cheng
  • 964
  • 2
  • 11
  • 24
2
votes
1 answer

QComboBox drop down button outside combo box frame

I'm trying to go outside combo box frame with this CSS Qt style sheet: QComboBox#tab_combo { margin: 0 26px 0 0; /* make room for the arrow */ padding: 2px 1px 2px 1px; min-width: 19px; min-height: 14px; max-height: 14px; width: 40px; height:…
Dmitry
  • 906
  • 1
  • 13
  • 32
2
votes
1 answer

QComboBox with NULL support

I'm using QComboBox to select unit (an arbitrary property of the object) from Units table. The problem is that object in my data model can have no unit (NULL in the table), in which case QComboBox shows value happened on top of the list. Select…
alxx
  • 9,897
  • 4
  • 26
  • 41
2
votes
1 answer

How to refresh contents of QCombobox in QTableView

I have QTableView which has QComboBox in one of the columns. The combobox is displaying data from a vector which get updates when I click a button. When I start the application the combobox displays all the items in vector. Now I press the button…
dev
  • 2,180
  • 2
  • 30
  • 46
2
votes
1 answer

How to get feedback from ComboBoxes created in a loop

I am trying to feed an unspecified number of comboboxes to a user. Once the user selects inputs for the combo boxes I want to be able to print out those combobox inputs after the submit button is clicked. Currently I can only print the last one…
iceAtNight7
  • 194
  • 1
  • 2
  • 10