Qt 5.10 Book Examples
chapter12
Roles
main.cpp
Go to the documentation of this file.
1
// ======================================================================
2
// main.cpp
3
// ======================================================================
4
// This file is a part of the book
5
// "Qt 5.10 Professional programming with C++"
6
// http://qt-book.com
7
// ======================================================================
8
// Copyright (c) 2017 by Max Schlee
9
// ======================================================================
10
11
#include <QtWidgets>
12
13
// ----------------------------------------------------------------------
14
int
main
(
int
argc,
char
** argv)
15
{
16
QApplication app(argc, argv);
17
QStringList lst;
18
lst <<
"Linux"
<<
"Windows"
<<
"MacOSX"
<<
"Android"
;
19
20
QStandardItemModel model(lst.size(), 1);
21
for
(
int
i = 0; i < model.rowCount(); ++i) {
22
QModelIndex index = model.index(i, 0);
23
QString str = lst.at(i);
24
model.setData(index, str, Qt::DisplayRole);
25
model.setData(index,
"ToolTip for "
+ str, Qt::ToolTipRole);
26
model.setData(index, QIcon(
":/"
+ str +
".jpg"
), Qt::DecorationRole);
27
}
28
29
QListView listView;
30
listView.setViewMode(QListView::IconMode);
31
listView.setModel(&model);
32
listView.show();
33
34
return
app.exec();
35
}
main
int main(int argc, char **argv)
Definition:
main.cpp:15
Generated by
1.8.14