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 ?
A combobox can be populated using the insert functions, insertItem() and insertItems() for example. Items can be changed with setItemText().
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.
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.
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);
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With