M CMakeLists.txt +4 -0
@@ 32,6 32,8 @@ if(ANDROID)
mainwindow.cpp
mainwindow.h
mainwindow.ui
+ quickitemdelegate.cpp
+ quickitemdelegate.h
)
else()
add_executable(quick-itemview
@@ 39,6 41,8 @@ else()
mainwindow.cpp
mainwindow.h
mainwindow.ui
+ quickitemdelegate.cpp
+ quickitemdelegate.h
)
endif()
M mainwindow.cpp +2 -0
@@ 1,5 1,6 @@
#include <QStringListModel>
#include "mainwindow.h"
+#include "quickitemdelegate.h"
#include "./ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
@@ 10,6 11,7 @@ MainWindow::MainWindow(QWidget *parent)
auto *model = new QStringListModel({"Foo", "Bar", "Baz"}, this);
ui_->treeView->setModel(model);
+ ui_->treeView->setItemDelegateForColumn(0, new QuickItemDelegate(this));
}
MainWindow::~MainWindow() = default;
A => quickitemdelegate.cpp +14 -0
@@ 0,0 1,14 @@
+#include <QPainter>
+#include "quickitemdelegate.h"
+
+QuickItemDelegate::QuickItemDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{
+}
+
+void QuickItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ painter->save();
+ painter->restore();
+}
A => quickitemdelegate.h +15 -0
@@ 0,0 1,15 @@
+#ifndef QUICKITEMDELEGATE_H
+#define QUICKITEMDELEGATE_H
+
+#include <QStyledItemDelegate>
+
+class QuickItemDelegate : public QStyledItemDelegate
+{
+public:
+ explicit QuickItemDelegate(QObject *parent = nullptr);
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override;
+};
+
+#endif // QUICKITEMDELEGATE_H