29 if (option.state & QStyle::State_MouseOver) {
31QT_WARNING_DISABLE_DEPRECATED
32 if ((QApplication::mouseButtons() & Qt::LeftButton) == 0)
33 pressedIndex = QModelIndex();
35 QBrush brush = option.palette.alternateBase();
36 if (index == pressedIndex)
37 brush = option.palette.dark();
38 painter->fillRect(option.rect, brush);
41 QStyledItemDelegate::paint(painter, option, index);
43 if (index.column() == 1 && index.model()->rowCount() > 1
44 && option.state & QStyle::State_MouseOver) {
45 QIcon icon((option.state & QStyle::State_Selected)
46 ?
":/qt-project.org/assistant/images/closebutton.png"
47 :
":/qt-project.org/assistant/images/darkclosebutton.png");
49 const QRect iconRect(option.rect.right() - option.rect.height(),
50 option.rect.top(), option.rect.height(), option.rect.height());
51 icon.paint(painter, iconRect, Qt::AlignRight | Qt::AlignVCenter);
58 : m_allowContextMenu(
true)
63 setItemDelegate((m_delegate =
new OpenPagesDelegate(
this)));
65 setTextElideMode(Qt::ElideMiddle);
66 setAttribute(Qt::WA_MacShowFocusRect,
false);
68 viewport()->setAttribute(Qt::WA_Hover);
69 setSelectionBehavior(QAbstractItemView::SelectRows);
70 setSelectionMode(QAbstractItemView::SingleSelection);
73 header()->setStretchLastSection(
false);
74 header()->setSectionResizeMode(0, QHeaderView::Stretch);
75 header()->setSectionResizeMode(1, QHeaderView::Fixed);
76 header()->resizeSection(1, 18);
78 installEventFilter(
this);
79 setUniformRowHeights(
true);
80 setContextMenuPolicy(Qt::CustomContextMenu);
82 connect(
this, &QAbstractItemView::clicked,
83 this, &OpenPagesWidget::handleClicked);
84 connect(
this, &QAbstractItemView::pressed,
85 this, &OpenPagesWidget::handlePressed);
86 connect(
this, &QWidget::customContextMenuRequested,
87 this, &OpenPagesWidget::contextMenuRequested);
164 QMouseEvent e(QEvent::MouseMove, vp->mapFromGlobal(cursorPos), cursorPos,
174 return QWidget::eventFilter(obj, event);
176 if (event->type() == QEvent::KeyPress) {
177 QKeyEvent *ke =
static_cast<QKeyEvent*>(event);
178 if (currentIndex().isValid() && ke->modifiers() == 0) {
179 const int key = ke->key();
180 if (key == Qt::Key_Return || key == Qt::Key_Enter
181 || key == Qt::Key_Space) {
182 emit setCurrentPage(currentIndex());
183 }
else if ((key == Qt::Key_Delete || key == Qt::Key_Backspace)
184 && model()->rowCount() > 1) {
185 emit closePage(currentIndex());
188 }
else if (event->type() == QEvent::KeyRelease) {
189 QKeyEvent *ke =
static_cast<QKeyEvent*>(event);
190 if (ke->modifiers() == 0
191 && (ke->key() == Qt::Key_Up || ke->key() == Qt::Key_Down)) {
192 emit setCurrentPage(currentIndex());
195 return QWidget::eventFilter(obj, event);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
This pure abstract function must be reimplemented if you want to provide custom rendering.