41class FixedRowHeightDelegate :
public QStyledItemDelegate
44 FixedRowHeightDelegate(QAbstractItemDelegate *inner, std::function<
int()> row_height, QObject *parent) :
45 QStyledItemDelegate(parent), inner_(inner), row_height_(std::move(row_height)) {}
47 void paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const override
50 inner_->paint(painter, option, index);
52 QStyledItemDelegate::paint(painter, option, index);
56 QSize sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index)
const override
58 QSize size = inner_ ? inner_->sizeHint(option, index) : QStyledItemDelegate::sizeHint(option, index);
59 int height = row_height_ ? row_height_() : 0;
61 size.setHeight(height);
66 bool helpEvent(QHelpEvent *event, QAbstractItemView *view,
const QStyleOptionViewItem &option,
const QModelIndex &index)
override
68 return inner_ ? inner_->helpEvent(event, view, option, index)
69 : QStyledItemDelegate::helpEvent(event, view, option, index);
73 QAbstractItemDelegate *inner_;
74 std::function<int()> row_height_;
88 view->setItemsExpandable(
false);
89 view->setRootIsDecorated(
false);
90 view->setUniformRowHeights(
true);
91 view->setFocusPolicy(Qt::NoFocus);
92 view->setMouseTracking(
true);
93 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
94 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
95 view->setFrameShape(QFrame::NoFrame);
96 view->setVisible(
false);