Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] QTreeView Basic understanding
I can't understand the QtreeView Model handling. Could someone please explain it with my example?
MainWindow::MainWindow(QWidget *parent) :
QList<int> sample; sample<<10<<11<<12<<13; //11 is child of 10 //13 is child of 12 //build treeModel of QAbstractItemModel ui->treeView->setModel(tree); sample=5; //change in TreeView??
Did you look at QStandardItemModel and QStandardItem to build your tree model ? I'm sure you will good examples in Qt Assistant and google. Also what is the explanation you are expecting ? Any change in model will be reflected in View. I just made sample which is very trivial.
Here whenever you change the list1, it should get reflected in view. Hope this helps.
i have various types of data(strings doubles and int) and i thought you need to specify the type in the model.
when i change your example it doesnt work with integers!
U can't set integers directly. There is no integer model like stringlistmodel. U need to list model with integers.
How this is exactly my question?
By using your model's setData method
I dont know how to create the model this was my first question!
I suggest you read the ModelView Programming in Qt Assistant. It clearly describes about different models, views. Try to understand how you can create different models. Qt Demo/Examples in your installation also contain many examples. Simple google hit also gave me many links with example. Enjoy model view programming.
Here is an official tutorial for model/view programming: http://qt-project.org/doc/qt-5/modelview.html
Here is a simple example that uses QStandardItemModel with QTreeView to visualize integers:
// Create model
auto model = new QStandardItemModel;
// Add data to model
for (int i = 0; i < 10; ++i)
auto item = new QStandardItem;
item->setData(i); // Set integer data
list << item;
// Create view to visualize the model
auto view = new QTreeView;
Note that there are many different models and many different views you can choose from. If you only want a list, you should use QListView instead of QTreeView.
thank you this will help me