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.

666 questions
87
votes
13 answers

How can I get the selected VALUE out of a QCombobox?

In Qt, I can get the selected text of a QComboBox by using the combobox->currentText() method. How can I get the selected value? I searched for help but I couldn't find a method currentData() which I expected to find. I could only find…
sabbour
  • 4,730
  • 4
  • 32
  • 33
57
votes
3 answers

QComboBox - set selected item based on the item's data

What would be the best way of selecting an item in a QT combo box out of a predefined list of enum based unique values. In the past I have become accustomed to .NET's style of selection where the item can be selected by setting the selected property…
cweston
  • 10,371
  • 17
  • 74
  • 104
41
votes
4 answers

How do you get the current text contents of a QComboBox?

Using pyqt4 and python 2.6, I am using a qcombobox to provide a list of options. I am having problems with using the selected option. I have been able to use a signal to trigger a method when the option is selected, but the problem is that when the…
Ben
  • 4,915
  • 7
  • 40
  • 57
35
votes
9 answers

How do I set the background color of a widget like combobox or double spin box?

I am trying to set the background color for a double spin box, and I am not sure what function I should use. I saw some function called SetBackgroundRole which accepts a Qt::ColorRole, but I am not sure how to use this one as well. Kindly let me…
AMM
  • 12,892
  • 19
  • 61
  • 74
34
votes
1 answer

How to set QComboBox to item from item's text in PyQt/PySide

Is it possible to set QComboBox to an item knowing only an item's text value? I am trying to avoid looping through for i in range(myCombobox.count()) just to find an item's index so it could be used to set the current index.
alphanumeric
  • 13,847
  • 39
  • 164
  • 305
27
votes
2 answers

Getting all items of QComboBox - PyQt4 (Python)

I have A LOT of QComboBoxes, and at a certain point, I need to fetch every item of a particular QComboBox to iterate through. Although I could just have a list of items that correspond to the items in the QComboBox, I'd rather get them straight from…
Anti Earth
  • 4,172
  • 11
  • 45
  • 79
26
votes
3 answers

How to add items to a QComboBox in PyQt/PySide

I need some help adding some items to a QComboBox. So I have two comboboxes, and one populates the other depending on the item selected. My question is that, using additem for new items, it works, but if I choose another option for the combobox, it…
IordanouGiannis
  • 3,541
  • 12
  • 52
  • 87
24
votes
6 answers

QCompleter Custom Completion Rules

I'm using Qt4.6 and I have a QComboBox with a QCompleter in it. The usual functionality is to provide completion hints (these can be in a dropdown rather than inline - which is my usage) based on a prefix. For example, given chicken soup chilli…
jcuenod
  • 48,573
  • 13
  • 58
  • 98
24
votes
3 answers

How do I set the QComboBox width to fit the largest item?

I have a QComboBox that I fill with QString using: comboBox->addItem(someString); When I start my GUI application the width of the QComboBox is always 70, even if the smallest item is much larger. How can I dynamically set the width of a QComboBox,…
Linoliumz
  • 2,008
  • 3
  • 25
  • 29
18
votes
3 answers

How to set non-selectable default text on QComboBox?

Using a regular QComboBox populated with items, if currentIndex is set to -1, the widget is empty. It would be very useful to instead have an initial descriptive text visible in the combo box(e.g. "--Select Country--", "--Choose Topic--", etc.)…
swalog
  • 4,069
  • 3
  • 27
  • 57
18
votes
2 answers

Set selected item for QComboBox

I have a simple QComboBox widget, which has 2 values inside: True and False. And I have a QString variable currValue, which is one of those values. I want to set my widget's current value with currValue. I thought that solution is the…
Karen Tsirunyan
  • 1,728
  • 5
  • 17
  • 29
17
votes
4 answers

Selecting QComboBox in QTableWidget

One cell in each row of a QTableWidget contains a combobox for (each row in table ... ) { QComboBox* combo = new QComboBox(); table->setCellWidget(row,col,combo); combo->setCurrentIndex(node.type()); …
qtnewbie
15
votes
3 answers

Qt Using Custom QItemDelegate for QTableView

I followed the Spin Box Delegate tutorial, which Qt provides, to try to implement my own QItemDelegate. It would be used to specify a QComboBox to represent data in a QTableView cell but it is not working. My biggest problem is that I don't know…
arnm
  • 1,545
  • 2
  • 16
  • 30
13
votes
1 answer

QComboBox - Select no entry

I have a QComboBox on my ui and set the model like this: QStringListModel* model = new QStringListModel; QStringList stringlist; stringlist << "Test1" << "Test2" << "Test3"; model->setStringList(stringlist); ui->comboBox->setModel(model); Now I…
iBent
  • 322
  • 2
  • 15
13
votes
2 answers

Show tooltip when the user selects item in QComboBox

I want to show the tooltip with the text and the time when user selects the item in list view (hovers the mouse on the item in the list view) of QCombobox. I'm using a custom QComboBox with QItemDelegate.
Wagmare
  • 1,234
  • 20
  • 52
1
2 3
44 45