Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting items in Qt combo box

Tags:

c++

combobox

qt

I'm very new to Qt. I'm following this tutorial http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html. There is a small mistake in this tutorial. Though it adds a combo box entry, text is not set. Can somebody tell me how to initialize the combo box, correctly.

Also, can somebody point out me if there are better tutorials for learning Qt ?

like image 844
danial weaber Avatar asked Nov 27 '12 14:11

danial weaber


People also ask

How to add items in ComboBox in Qt?

A combobox can be populated using the insert functions, insertItem() and insertItems() for example. Items can be changed with setItemText().

What is a widget in Qt?

Widgets are the primary elements for creating user interfaces in Qt. Widgets can display data and status information, receive user input, and provide a container for other widgets that should be grouped together. A widget that is not embedded in a parent widget is called a window.

What is the function of combo box?

A ComboBox displays a text box combined with a ListBox, which enables the user to select items from the list or enter a new value. The DropDownStyle property specifies whether the list is always displayed or whether the list is displayed in a drop-down.


3 Answers

At last, I got the right answer. I have provided it below, hopefully it will be useful to other beginners:

QStringList list=(QStringList()<<"red"<<"yellow"<<"blue");
comboBox->addItems(list);
like image 138
danial weaber Avatar answered Oct 11 '22 20:10

danial weaber


When your in Qt Designer you could just double click on the QComboBox and an EditComboBox screen will appear. There you just click on the plus or minus sign to easily add items to the list of objects.Hope this helps.This way you don't have to do it with code though.

like image 6
user2633954 Avatar answered Oct 11 '22 20:10

user2633954


This tutorial is made for Qt 4.2, we are now at Qt 4.8. You should find what you are looking for here http://qt-project.org/doc/qt-4.8/how-to-learn-qt.html

Little advice, try not to use Qt creator to design your Gui until you understand how to do it with code, you will do less mistakes (and know what to look for when you do).

like image 5
Jeremie Avatar answered Oct 11 '22 21:10

Jeremie