I'm working on Qt Creator and I am completely new to it. I want to have a list box which is loaded with the data when I run the program and I choose a value from the list box and press button and do some operation on that selected value.
Is there any option for a list box in Qt creator? I have seen drag and drop listbox and listview but dont know which to use and how to use it .
Also, where to write a code to load the list automatica开发者_StackOverflow中文版lly?
My project has many files like:
- mainwindow.h
- mainwindow.cpp
- mainwindow.ui
- mainwindow.c
- main.c
Could someone help me with this listbox thing and also help with the syntax.
Thanks
QT4 ListBox equivalent is QListWidget
You can add it to your project with opening mainwindow.ui
You can add QString or QListWidgetItem to your QListWidget
with syntax
QListWidget* widget = new QListWidget();
widget->addItem("Foo");
// To Insert Item A specific row
widget->insertItem(0, "Bar");
// To Access Selected Item
widget->currentItem();
You can write your function prototypes in mainwindow.h and code in mainwindow.cpp
To load the list content automatically you can add your code to the constructor function of the mainwindow class
If you don't have an idea about how to do these, start with a beginners guide to QT
精彩评论