Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QtWidgets/QApplication>
- #include <QtCore/QAbstractListModel>
- #include <QtGui/QPixmap>
- #include <QtGui/QPainter>
- #include <QtGui/QColor>
- #include <QtWidgets/QListView>
- class Model : public QAbstractListModel {
- public:
- Model() {
- image = new QPixmap(70,70);
- QPainter painter(image);
- painter.fillRect(image->rect(), QColor("red"));
- }
- int rowCount(const QModelIndex & parent = QModelIndex()) const {
- return 10;
- }
- QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const {
- switch (role) {
- case Qt::DisplayRole:
- return QString("Item %1").arg(index.row());
- case Qt::DecorationRole:
- if (index.row() % 2) {
- return *image;
- }
- }
- return QVariant();
- }
- private:
- QPixmap* image;
- };
- #include <QtWidgets/QDialog>
- class QListViewIconMode : public QDialog {
- public:
- QListViewIconMode(QWidget *parent = nullptr) : QDialog(parent) {
- auto listView = new QListView(this);
- listView->setGeometry(QRect(10, 10, 581, 381));
- listView->setViewMode(QListView::IconMode);
- listView->setModel(new Model());
- }
- };
- int main(int argc, char *argv[]) {
- QApplication a(argc, argv);
- QListViewIconMode w;
- w.show();
- return a.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement