From 5401f6bee775c773447c555be02ee4a4fab5c1a1 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Fri, 19 Jan 2024 23:25:37 +0100 Subject: [PATCH 1/3] (fix) StarEditor: unset Selected state if required --- src/library/stareditor.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/library/stareditor.cpp b/src/library/stareditor.cpp index 1cc2154e6d5..743c993e346 100644 --- a/src/library/stareditor.cpp +++ b/src/library/stareditor.cpp @@ -47,9 +47,12 @@ void StarEditor::paintEvent(QPaintEvent*) { // If the editor cell is selected set the respective flag so we can use the // palette's 'HighlightedText' font color for the brush StarRating will use // to fill the star/diamond polygons with. + // Else, unset it and we use the regular color. QItemSelectionModel* selectionModel = m_pTableView->selectionModel(); if (selectionModel && selectionModel->isSelected(m_index)) { m_styleOption.state |= QStyle::State_Selected; + } else { + m_styleOption.state &= ~QStyle::State_Selected; } QPainter painter(this); From ab2d9b6ce757bcb19b5f24023d5bb2cd75589ad5 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Fri, 19 Jan 2024 22:09:25 +0100 Subject: [PATCH 2/3] (cleanup) WStarRating: remove unneeded QStyleOption --- src/widget/wstarrating.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/widget/wstarrating.cpp b/src/widget/wstarrating.cpp index f660b239184..3f8364d7cbd 100644 --- a/src/widget/wstarrating.cpp +++ b/src/widget/wstarrating.cpp @@ -35,10 +35,7 @@ void WStarRating::setup(const QDomNode& node, const SkinContext& context) { } QSize WStarRating::sizeHint() const { - QStyleOption option; - option.initFrom(this); - - // Center rating horizontally + // Center rating horizontally and vertically m_contentRect.setRect( (size().width() - m_visualStarRating.sizeHint().width()) / 2, (size().height() - m_visualStarRating.sizeHint().height()) / 2, From 923abdf15b7b238cf1d1f1f8961d2a3ca2d11ad8 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Sat, 20 Jan 2024 00:31:05 +0100 Subject: [PATCH 3/3] (cleanup) StarEditor: re-arrange paint steps (StarRating has a PainterScope) --- src/library/stardelegate.cpp | 3 ++- src/library/stareditor.cpp | 12 +++++------- src/library/starrating.cpp | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/library/stardelegate.cpp b/src/library/stardelegate.cpp index ec0480a0cb9..1d0cba4c05f 100644 --- a/src/library/stardelegate.cpp +++ b/src/library/stardelegate.cpp @@ -18,7 +18,8 @@ void StarDelegate::paintItem( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { - // let the editor do the painting if this cell is currently being edited + // Let the editor do the painting if this cell is currently being edited. + // Note: if required, the focus border will be drawn by the editor. if (index == m_currentEditedCellIndex) { return; } diff --git a/src/library/stareditor.cpp b/src/library/stareditor.cpp index 743c993e346..269015f34d7 100644 --- a/src/library/stareditor.cpp +++ b/src/library/stareditor.cpp @@ -65,13 +65,6 @@ void StarEditor::paintEvent(QPaintEvent*) { style->drawControl(QStyle::CE_ItemViewItem, &m_styleOption, &painter, m_pTableView); } - // Draw a border if the color cell has focus - if (m_styleOption.state & QStyle::State_Selected) { - // QPainterScope in drawBorder() and shift down? - TableItemDelegate::drawBorder(&painter, m_pFocusBorderColor, m_styleOption.rect); - } - - // Starrating scales the painter so do this after painting the border. // Set the palette appropriately based on whether the row is selected or // not. We also have to check if it is inactive or not and use the // appropriate ColorGroup. @@ -89,6 +82,11 @@ void StarEditor::paintEvent(QPaintEvent*) { } m_starRating.paint(&painter, m_styleOption.rect); + + // Draw a border if the color cell is selected + if (m_styleOption.state & QStyle::State_Selected) { + TableItemDelegate::drawBorder(&painter, m_pFocusBorderColor, m_styleOption.rect); + } } bool StarEditor::eventFilter(QObject* obj, QEvent* event) { diff --git a/src/library/starrating.cpp b/src/library/starrating.cpp index d903a5e8590..e807c59802c 100644 --- a/src/library/starrating.cpp +++ b/src/library/starrating.cpp @@ -37,6 +37,7 @@ void StarRating::paint(QPainter* painter, const QRect& rect) const { PainterScope painterScope(painter); // Assume the painter is configured with the right brush. painter->setRenderHint(QPainter::Antialiasing, true); + // Don't draw outlines, only fill the polygons painter->setPen(Qt::NoPen); // Center vertically inside the table cell, and also center horizontally