From c796677a7b8f049b2bb902f1ec7f2251f295ead3 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig <jens.bache-wiig@digia.com> Date: Mon, 27 May 2013 13:27:01 +0200 Subject: [PATCH] Fix item view selection color We need to update the active palette text color every time the state changes. Change-Id: I7861eb4be76ccaeb58e9ff9aea58fa54d4f8d4c9 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com> --- src/private/qquickstyleitem.cpp | 11 +++++++---- src/styles/Desktop/TableViewStyle.qml | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/private/qquickstyleitem.cpp b/src/private/qquickstyleitem.cpp index cfbb36c89..422d9a8e5 100644 --- a/src/private/qquickstyleitem.cpp +++ b/src/private/qquickstyleitem.cpp @@ -938,8 +938,8 @@ QVariant QQuickStyleItem::styleHint(const QString &metric) if (metric == "comboboxpopup") { return qApp->style()->styleHint(QStyle::SH_ComboBox_Popup, m_styleoption); } else if (metric == "highlightedTextColor") { - QPalette pal = qApp->palette(); - pal.setCurrentColorGroup(active()? QPalette::Active : QPalette::Inactive); + QPalette pal = QApplication::palette("QAbstractItemView"); + pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup()); return pal.highlightedText().color().name(); } else if (metric == "textColor") { QPalette pal = qApp->palette(); @@ -1192,8 +1192,11 @@ void QQuickStyleItem::paint(QPainter *painter) pixmap.fill(Qt::transparent); QPainter pixpainter(&pixmap); qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, m_styleoption, &pixpainter); - if (!qApp->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected) && selected()) - pixpainter.fillRect(m_styleoption->rect, m_styleoption->palette.highlight()); + if ((style() == "mac" || !qApp->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected)) && selected()) { + QPalette pal = QApplication::palette("QAbstractItemView"); + pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup()); + pixpainter.fillRect(m_styleoption->rect, pal.highlight()); + } QPixmapCache::insert(pmKey, pixmap); } painter->drawPixmap(0, 0, pixmap); diff --git a/src/styles/Desktop/TableViewStyle.qml b/src/styles/Desktop/TableViewStyle.qml index da6a47e55..52fb96357 100644 --- a/src/styles/Desktop/TableViewStyle.qml +++ b/src/styles/Desktop/TableViewStyle.qml @@ -46,8 +46,8 @@ ScrollViewStyle { readonly property TableView control: __control property bool activateItemOnSingleClick: __styleitem.styleHint("activateItemOnSingleClick") - property color textColor: __styleitem.styleHint("textColor") - property color highlightedTextColor: __styleitem.styleHint("highlightedTextColor") + property color textColor: __styleitem.textColor + property color highlightedTextColor: __styleitem.highlightedTextColor property StyleItem __styleitem: StyleItem{ property color textColor: styleHint("textColor") @@ -55,6 +55,10 @@ ScrollViewStyle { elementType: "item" visible: false active: control.activeFocus + onActiveChanged: { + highlightedTextColor = styleHint("highlightedTextColor") + textColor = styleHint("textColor") + } } property Component headerDelegate: StyleItem { -- GitLab