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

Setting style in using QStyleFactory from a list of styles in a QComboBox

I've been implementing an application using PyQt4. In this application I want to set the style according to the user's choice, and I want to set the style without restarting the dialog again. Here's my piece of code which is affecting the styling…
dragfire
  • 435
  • 1
  • 7
  • 20
5
votes
1 answer

QT - How to retrieve QVariant Values from combobox?

I'm using QVariant to store a object inside of a Qcombobox, This appears to work fine. This is the implementing code: Add type to QVariant in header: Q_DECLARE_METATYPE(CDiscRecorder*) pDiscRecorder Casted as CDiscRecorder: CDiscRecorder*…
rreeves
  • 2,408
  • 6
  • 39
  • 53
5
votes
6 answers

remove items from QComboBox from ui

I am trying to tweak the ui of a QComboBox in a way that the user can remove items from the drop down list (without first selecting them). The background is that I am using the QComboBox to indicate which data file is open right now. I am also using…
Peter
  • 543
  • 1
  • 5
  • 13
5
votes
1 answer

Autocompletion with qcompleter for fragments in the middle of a word

Is there an example available of a QCompleter subclass that will provide autocompletions for fragments that appear in the middle of words? eg: Suppose you have the wordlist { "apple", "pear", "banana" }. When the user types 'p', the suggested…
Kevin
4
votes
3 answers

Style QComboBox popup menu margin Qt 4

After countless hours trying to style a QComboBox, I'm stuck with the top and bottom margin where the items are inserted. I would like to either remove or apply a background-color to the popup menu top and bottom white spaces. QComboBox screen…
Kirell
  • 9,228
  • 4
  • 46
  • 61
4
votes
3 answers

Add QCombobox inside QTreeview specific cell

I was trying to insert a QCombobox only in some specific cells of my QTreeview. As I read, I think that I need to create my delegate (that I've created). But I don't understand how to insert this in my treeview. I want to realize this: This is my…
Tex'N'Duet
  • 301
  • 2
  • 13
4
votes
1 answer

How do i use QComboBox.setPlaceholderText?

In Qt 5.15 the placeholderText property was introduced - link to documentation However using setPlaceholderText doesn't do anything for me. When running the code below i don't get any text in the QComboBox (unless of course i select one of the three…
sunyata
  • 1,843
  • 5
  • 27
  • 41
4
votes
3 answers

How to force a model to update QComboBox when data changed?

I created model for QComboBox: #ifndef QCOMBOBOXMODEL_H #define QCOMBOBOXMODEL_H #include class QComboBoxModel : public QAbstractListModel { public: QComboBoxModel(QObject *parent=nullptr); int rowCount(const QModelIndex &)…
Vasilij Altunin
  • 754
  • 1
  • 5
  • 18
4
votes
1 answer

QComboBox: Only show the icons when expanded

Starting from a "normal" QCombobox I'd like to get a QCombobox that only shows the icon when it's expanded, but not when it's collapsed. I've found several answers to similar questions, but all of them show code for much more complex situations…
a.l.e
  • 792
  • 8
  • 16
4
votes
3 answers

Can QComboBox items text consist of 2 colors?

For example for string "Elon Musk": "Elon" text color is red; "Musk" text color is green; Thanks in advance for any help you can provide
Igor
  • 53
  • 3
4
votes
2 answers

How to change QComboBox items height size?

How to change QComboBox items height size? I want change only height - I need it larger. Its strange that there are no any functions for this purposes.
AeroSun
  • 2,401
  • 2
  • 23
  • 46
4
votes
4 answers

How to make QCombobox painting item delegate for it's current Item? (Qt 4)

QCombobox set Item delegate not painting for current Item.. I am trying to create a combo box showing different line types (Solid, Dotted, Dash etc). Currently i am setting item delegate for its content so as to draw/paint line type instead of…
r4nj33t
4
votes
2 answers

QComboBox elided text on selected item

So, I have a QComboBox. If the currentText() is too long for the widget then I want to show an ellipsis. Like this : So : void MyComboBox::paintEvent(QPaintEvent * ) { QStylePainter painter(this); QStyleOptionComboBox opt; …
andrea.marangoni
  • 1,499
  • 8
  • 22
4
votes
2 answers

How to create combo-box QItemDelegate

I implemented the following delegate, to provide a combobox in a QTableView. The use case is to replace a column (key) that is generally meaningless for the user (e.g. a numerical id) with a text equivalent. The snippet below works (also for saving…
fralau
  • 3,279
  • 3
  • 28
  • 41
4
votes
2 answers

How to position an added widget to a layout based on another widget in the same layout?

In my GUI, I would like to add a QComboBox to a verticalLayout programmatically based on a a signal triggered by specific action. The following code works fine and the widget is added: QComboBox* userOptions = new…
McLan
  • 2,552
  • 9
  • 51
  • 85