# HG changeset patch # User Yuya Nishihara # Date 1579270987 -32400 # Fri Jan 17 23:23:07 2020 +0900 # Node ID 9a37651f04bc4a508b02903e21ac21f70e027fa1 # Parent 5856113283730ea67c4efc4c02222256c845fc54 add stub ItemDelegate diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ mainwindow.cpp mainwindow.h mainwindow.ui + quickitemdelegate.cpp + quickitemdelegate.h ) else() add_executable(quick-itemview @@ -39,6 +41,8 @@ mainwindow.cpp mainwindow.h mainwindow.ui + quickitemdelegate.cpp + quickitemdelegate.h ) endif() diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,5 +1,6 @@ #include #include "mainwindow.h" +#include "quickitemdelegate.h" #include "./ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) @@ -10,6 +11,7 @@ auto *model = new QStringListModel({"Foo", "Bar", "Baz"}, this); ui_->treeView->setModel(model); + ui_->treeView->setItemDelegateForColumn(0, new QuickItemDelegate(this)); } MainWindow::~MainWindow() = default; diff --git a/quickitemdelegate.cpp b/quickitemdelegate.cpp new file mode 100644 --- /dev/null +++ b/quickitemdelegate.cpp @@ -0,0 +1,14 @@ +#include +#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(); +} diff --git a/quickitemdelegate.h b/quickitemdelegate.h new file mode 100644 --- /dev/null +++ b/quickitemdelegate.h @@ -0,0 +1,15 @@ +#ifndef QUICKITEMDELEGATE_H +#define QUICKITEMDELEGATE_H + +#include + +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