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
6
votes
1 answer

PyQT5 QComboBox - get value of combobox

I am still very new to Qt but I am developing a type of calculator and want to use a combobox to select a coefficient. I have had success creating a combobox with a liststore in pyGT but it appears pyQT is quite different. I am having a hard time…
Judson
  • 73
  • 1
  • 1
  • 4
6
votes
2 answers

Remove QComboBox listView shadow effect

By default, the QComboBox listview has shadow effect. Is there a way to remove it? Is the shadow controlled from QStyle or in some other way?
6
votes
1 answer

How to center text in QComboBox?

I've tried using QComboBox's model() with no apparent success. I wonder if it would be possible to align a text at the center of QCombobox. Aside from text alignment it seems the item's font is not effected by changing its PointSize.... …
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
6
votes
1 answer

PyQt: How to customize QComboBox item appearance

Is it possible to create a combo-box item first, then set its display properties (such as background-color, icon, font-color, font-size, etc) and only then add it to the combo-box using QComoboBox.addItem() method? As it is now, I am stuck…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
6
votes
3 answers

Qt: c++: how to fill QComboBox using QStringList

I am trying to add items to QComboBox using insertItems function as follow: QStringList sequence_len = (QStringList() << QApplication::translate("MainWindow", "1", 0, QApplication::UnicodeUTF8) << QApplication::translate("MainWindow", "2", 0,…
hashDefine
  • 1,491
  • 6
  • 23
  • 33
6
votes
2 answers

Overloaded pyside signals (QComboBox)

Using a QComboBox with pyside, I know how to connect the signal and use the index that it sends. But what about the unicode argument? If I'd prefer to connect to something that wants the string from the combobox, is that…
user985366
  • 1,635
  • 3
  • 18
  • 39
5
votes
1 answer

Separate user interaction from programmical change: PyQt, QComboBox

I have several QComboBoxes in my PyQt4/Python3 GUI and they are filled with some entries from a database during the initialisation. Initial CurrentIndex is set to 0. There is also a tick box which changes the language of the items in my combo boxes.…
Ekaterina Mishina
  • 1,633
  • 5
  • 20
  • 23
5
votes
5 answers

QComboBox - How to set hint text on combo box

The application GUI I working requires a combo box for user to select item. When the application starts, the combo box will show a hint text something like "Please select" instead of showing the first item of the combo box. I cannot find any method…
fucai1116
  • 191
  • 3
  • 5
5
votes
1 answer

Setting QStyleOptionComboBox.currentText does not have any effect on the drawn widget

I want to draw a QComboBox inside a delegate, which works fine except that I can't figure out how to draw the inital text that's visible inside the combo box. The documentation says that QStyleOptionComboBox.currentText holds: "the text for the…
WolfgangP
  • 3,195
  • 27
  • 37
5
votes
3 answers

How to get the current value of a QComboBox with a model with two columns?

I have a QComboBox with a QSqlQueryModel as its model. The model is constructed from a database with SELECT type_id, type FROM types where type_id is int and type is a varchar. I set the QComboBox visible column with the setModelColumn(1) function,…
Aba
  • 673
  • 6
  • 11
5
votes
1 answer

Filter with QComboBox C++

I want to create an editable QComboBox which filters results according to the search query and updates the dropdown entries accordingly. After reading How do I Filter the PyQt QCombobox Items based on the text input? I tried to implement something…
Nishad
  • 102
  • 1
  • 3
  • 9
5
votes
2 answers

How to use QComboBox as delegate with QTableView

The code below creates a single QTableView. Double-clicking its item will set it with a delegated QComboBox. Problem: When the ComboBox is clicked its pull-down menu shows up momentary and then it collapses back to its unrolled state. If the…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
5
votes
1 answer

Qt - How to use rich text in a QComboBox?

I am trying to use rich text in a QComboBox but it does not support it. Perhaps I should write a subclass? But I am unsure on what I would need to override as I have never done anything like this before. Please help. Thanks!
Aaron McKellar
  • 627
  • 4
  • 10
  • 20
5
votes
1 answer

QComboBox with checkboxes

I'm creating QComboBox with checkboxes. How I can prevent collapsing of view on mouse clicking? I want to be able to set up checkboxes, but each time I click on item - drop-down of QComboBox is collapsed. Note: currently I'm debugging Qt sources and…
Dmitry Sazonov
  • 8,801
  • 1
  • 35
  • 61
5
votes
1 answer

Qt how to change the highlight color of a specific QComboBox item

I'm trying to make the highlight transparent for a QComboBox. The color of this QComboBox also changes based on the selected index. Here is my best solution so far: switch(comboBox->currentIndex()) { case 0: comboBox->setStyleSheet("QWidget…
Jared Price
  • 5,217
  • 7
  • 44
  • 74