An overview of the Qt Model View architecture and practical examples of how to use this architecture for presenting large data sets in your application user interface.
3. Contents
● An Overview of the Qt Model View Architecture
● An Introduction to the Item Model Interface
● Customized Item Filtering
● Customized Item Painting
● More Models and Hierarchies
16. #include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
int rows = 4;
int columns = 1;
QStandardItemModel model(rows, columns);
for (int r = 0; r < model.rowCount(); ++r) {
QModelIndex index = model.index(r, 0);
model.setData(index, "hello");
}
QTableView view;
view.setModel(&model);
view.show();
return app.exec();
}
17. Model Interface View
hello
? hello
hello
hello
Data Structure
18.
19.
20.
21. // we start with a 4x1 table
QStandardItemModel model(4, 1);
for (int r = 0; r < model.rowCount(); ++r) {
QModelIndex index = model.index(r, 0);
model.setData(index, "hello");
// let's add a 1x1 sub-table
QModelIndex parent = index
model.insertRow(0, parent);
model.insertColumn(0, parent);
// then we can set the data in cell [0,0]
QModelIndex child = mode.index(0, 0, parent);
model.setData(child, “world”);
}
22. Model Interface View
world
hello
? hello
hello
world
world
hello
world
Data Structure
23. Model
Model Interface
Custom API
Data Structure
24. #include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTreeWidget widget;
for (int i = 0; i < 4; ++i) {
QTreeWidgetItem *parent =
new QTreeWidgetItem(&widget, QStringList("hello"));
new QTreeWidgetItem(parent, QStringList("world"));
}
widget.show();
app.exec();
}
30. T Model Interface
he
● A Generic Interface to Data Structures
● M od els Are Interchangeab le
● Views Are Interchangeab le
● M od els and Selections Are Sharab le
70. What we have covered
● The Qt Model View Architecture
● The Item Model Interface
● Customized Item Filtering
● Customized Item Painting
● Hierarchical Models