QStandardItem is a class provided by Qt libraries, which is used for providing data in a tree view. It allows developers to manage and manipulate data using a hierarchical structure and is widely used in GUI development.
Example 1: Adding Items to a Tree View
QStandardItem* item = new QStandardItem("Item 1"); QStandardItem* childItem = new QStandardItem("Child Item 1"); item->appendRow(childItem); QStandardItemModel* model = new QStandardItemModel(); model->appendRow(item);
In this example, we create a new QStandardItem and append a child item to it. Then we create a QStandardItemModel and add the item we created. This code will add an item and its child item to a tree view.
Example 2: Retrieving Data from a Tree View
QModelIndex index = ui->treeView->currentIndex(); QStandardItemModel* model = qobject_cast(ui->treeView->model()); QStandardItem* item = model->itemFromIndex(index);
In this example, we retrieve the currently selected item from a tree view. We first retrieve the index of the selected item, then find the QStandardItemModel associated with the tree view. Finally, we retrieve the QStandardItem associated with the index. This code will allow developers to retrieve data from a tree view.
Package/Library: Qt Libraries
C++ (Cpp) QStandardItem - 30 examples found. These are the top rated real world C++ (Cpp) examples of QStandardItem extracted from open source projects. You can rate examples to help us improve the quality of examples.