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
4
votes
2 answers

QComboBox connect

I need to call a function with currentIndex+1 when the currentIndex of a QComboBox changes. I'm struggling with the syntax this morning: // call function readTables(int) when currentIndex changes. connect(ui->deviceBox,…
Jocala
  • 243
  • 1
  • 4
  • 16
4
votes
1 answer

Qt : How to get QComboBox item text at an arbitrary index (not the currently selected item)

Extracting text of the selected QComboBox item is well known, but how do I get the text in a QComboBox for an arbitrary index item (not necessarily the one selected)?
daj
  • 6,962
  • 9
  • 45
  • 79
4
votes
1 answer

How to close QComboBox editor in delegate when user chooses item

I have QStyledDelegate which creates QComboBox editor in createEditor() method. The editor closes only when user chooses an item in the list and the presses Enter key. I want the editor to be closed only when user chooses the item. How to do…
Alexander_KH
  • 189
  • 12
4
votes
1 answer

How can I move the icon above text in QComboBox

I have been looking at the QComboBox source file for a while now and I can't figure out what I need to change so that the icon is positioned above text in a QComboBox. |-----------------------| | ----- | | |icn| | | …
4
votes
3 answers

How to display superscript in QComboBox item?

I want to display 10-8 in QComboBox item. But it displays "sup" tags.
Alen
  • 53
  • 5
4
votes
1 answer

QComboBox:focus Qt Style Sheet

I have an editable combo box on the input form, which background must change when it receives focus. The following code works perfect for QLineEdit but has no effect on QComboBox. QLineEdit, QComboBox { background-color: green; } QLineEdit:focus,…
user1364014
4
votes
2 answers

How to add a string to QCombobox

Normally I would add items to a QCombobox by saying: QCombobox cbb; cbb.addItem("Hello"); But if I try this I get an error: QComboBox cbb; QString * s = new QString("hallo"); cbb.addItem(s); error: no matching function for call to…
Frank
  • 2,446
  • 7
  • 33
  • 67
4
votes
1 answer

PyQt: How to change currentIndex in QComboBox when custom QAbstractListModel data changed

I've read some examples on how to define a custom model for a QComboBox widget. Here's how I defined my model: class LevelListModel(QAbstractListModel): def __init__(self, parent=None, *args): """ datain: a list where each item is a row …
Heisenbug
  • 38,762
  • 28
  • 132
  • 190
4
votes
1 answer

QComboBox not calling Delegate methods

I want to customize a QComboBox by inserting QWidgets (instead of strings) through a model and a delegate: QComboBox *cb = new QComboBox(this); FeatureModel *featureModel = new FeatureModel(cb); cb->setModel(featureModel); ComboBoxItemDelegate…
Magnus
  • 55
  • 1
  • 6
3
votes
1 answer

Deactivate QSpinBox if a certain value from QComboBox is selected

Is it possible to deactivate a QSpinBox if a certain value is chosen in a QComboBox. I've tried several things, but either the QSpinbox is deactived all the time or it wont deactivate at all.
buddy
  • 821
  • 2
  • 12
  • 30
3
votes
1 answer

PyQt4 QComboBox Signals and Slots

is there a way to create a signal that asserts when a combo box is opened and user uses the up - down arrows on the keyboard to select an item. So far the Qt4 reference lists signals that activate only after a mouse click or return key hit. I…
Dave
  • 41
  • 4
3
votes
1 answer

PyQT combobox only react on user interaction

I have a listbox that you can select users in. To the left of that is a combobox listing the available groups the user can be put it. If the user is in a group, the combobox will automatically be set to that group. I want to make it so when you…
directedition
  • 11,145
  • 18
  • 58
  • 79
3
votes
1 answer

Pyqt5: How can I create a manually editable QDateEdit widget?

I know that for QComboBox there is method called editable with which you can manually edit current value: combo.setEditable(True). I could not find something similar with QDateEdit. I want user be able to delete entire date string and manually enter…
jabbarlee
  • 110
  • 2
  • 11
3
votes
2 answers

PyQt5 checkable combo box: display list of checked items

Based on https://stackoverflow.com/a/22775990/7894940 checkable combo box implementation, I want to go one step further and be able to display the list of the checked items directly on the main QComboBox label, i.e. when the displayed text of the…
rubebop
  • 392
  • 1
  • 7
  • 17
3
votes
2 answers

Show item in a QComboBox but not in its popup list

I have some code to use a combobox to show a list of products. I would like to show "Select product" in the combobox: products = ["Select product", "223", "51443" , "7335"] but I do not want the user to be able to select the "Select product" item.…
hope
  • 39
  • 4