diff options
-rw-r--r-- | src/controls/Private/qquickstyleitem.cpp | 70 | ||||
-rw-r--r-- | src/controls/Private/qquickstyleitem_p.h | 1 |
2 files changed, 67 insertions, 4 deletions
diff --git a/src/controls/Private/qquickstyleitem.cpp b/src/controls/Private/qquickstyleitem.cpp index d794d1da..49baa1fd 100644 --- a/src/controls/Private/qquickstyleitem.cpp +++ b/src/controls/Private/qquickstyleitem.cpp @@ -264,6 +264,8 @@ void QQuickStyleItem::initStyleOption() (sizeHint == "small") ? QPlatformTheme::SmallFont : QPlatformTheme::SystemFont; + bool needsResolvePalette = true; + switch (m_itemType) { case Button: { if (!m_styleoption) @@ -330,6 +332,8 @@ void QQuickStyleItem::initStyleOption() opt->features = QStyleOptionViewItem::HasDisplay; opt->text = text(); opt->textElideMode = Qt::ElideRight; + resolvePalette(); + needsResolvePalette = false; QPalette pal = m_styleoption->palette; pal.setBrush(QPalette::Base, Qt::NoBrush); m_styleoption->palette = pal; @@ -715,6 +719,9 @@ void QQuickStyleItem::initStyleOption() if (!m_styleoption) m_styleoption = new QStyleOption(); + if (needsResolvePalette) + resolvePalette(); + m_styleoption->styleObject = this; m_styleoption->direction = qApp->layoutDirection(); @@ -756,6 +763,62 @@ void QQuickStyleItem::initStyleOption() } +void QQuickStyleItem::resolvePalette() +{ + QPlatformTheme::Palette paletteType = QPlatformTheme::SystemPalette; + switch (m_itemType) { + case Button: + paletteType = QPlatformTheme::ButtonPalette; + break; + case RadioButton: + paletteType = QPlatformTheme::RadioButtonPalette; + break; + case CheckBox: + paletteType = QPlatformTheme::CheckBoxPalette; + break; + case ComboBox: + case ComboBoxItem: + paletteType = QPlatformTheme::ComboBoxPalette; + break; + case ToolBar: + case ToolButton: + paletteType = QPlatformTheme::ToolButtonPalette; + break; + case Tab: + case TabFrame: + paletteType = QPlatformTheme::TabBarPalette; + break; + case Edit: + paletteType = QPlatformTheme::TextEditPalette; + break; + case GroupBox: + paletteType = QPlatformTheme::GroupBoxPalette; + break; + case Header: + paletteType = QPlatformTheme::HeaderPalette; + break; + case Item: + case ItemRow: + paletteType = QPlatformTheme::ItemViewPalette; + break; + case Menu: + case MenuItem: + paletteType = QPlatformTheme::MenuPalette; + break; + case MenuBar: + case MenuBarItem: + paletteType = QPlatformTheme::MenuBarPalette; + break; + default: + break; + } + + const QPalette *platformPalette = QGuiApplicationPrivate::platformTheme()->palette(paletteType); + if (platformPalette) + m_styleoption->palette = *platformPalette; + // Defaults to SystemPalette otherwise +} + /* * Property style * @@ -1125,11 +1188,9 @@ 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 = QApplication::palette("QAbstractItemView"); - pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup()); - return pal.highlightedText().color().name(); + return m_styleoption->palette.highlightedText().color().name(); } else if (metric == "textColor") { - QPalette pal = qApp->palette(); + QPalette pal = m_styleoption->palette; pal.setCurrentColorGroup(active()? QPalette::Active : QPalette::Inactive); return pal.text().color().name(); } else if (metric == "focuswidget") { @@ -1608,6 +1669,7 @@ void QQuickStyleItem::paint(QPainter *painter) frame.midLineWidth = 0; frame.rect = m_styleoption->rect; frame.styleObject = this; + frame.palette = m_styleoption->palette; qApp->style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, painter); } } diff --git a/src/controls/Private/qquickstyleitem_p.h b/src/controls/Private/qquickstyleitem_p.h index a13cd4cc..8d296f25 100644 --- a/src/controls/Private/qquickstyleitem_p.h +++ b/src/controls/Private/qquickstyleitem_p.h @@ -192,6 +192,7 @@ public: void setContentHeight(int arg); virtual void initStyleOption (); + void resolvePalette(); Q_INVOKABLE qreal textWidth(const QString &); Q_INVOKABLE qreal textHeight(const QString &); |