From aef084fc06e325c9b206c274d5b297660b7c671f Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Tue, 28 Sep 2010 12:56:35 +0200 Subject: Fix a color propagation issue with Combobox line edit Some pixmap based themes were affected by this issue since they needed to resolve the palette against the widget and the lineedit palette was already resolved. We now set the palette on the lineedit when you modify the parent palette. You can still maintain a separate palette on the lineedit, but you have to set it after the parent has been set. We can remove some workarounds for plastique and vista style due to this. Task-number: QTBUG-5950 Reviewed-by: ogoffart --- dist/changes-4.8.0 | 1 + src/gui/styles/qplastiquestyle.cpp | 5 +---- src/gui/styles/qwindowsvistastyle.cpp | 4 ---- src/gui/widgets/qcombobox.cpp | 2 ++ tests/auto/qcombobox/tst_qcombobox.cpp | 12 ++++++++++++ 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dist/changes-4.8.0 b/dist/changes-4.8.0 index 0c28274..f8ca4bc 100644 --- a/dist/changes-4.8.0 +++ b/dist/changes-4.8.0 @@ -42,6 +42,7 @@ QtGui ----- - QTabBar: reduced minimumSizeHint if ElideMode is set. + - QComboBox: Fixed a color propagation issue with the lineedit. [QTBUG-5950] QtOpenGL -------- diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp index 4690a71..8772294 100644 --- a/src/gui/styles/qplastiquestyle.cpp +++ b/src/gui/styles/qplastiquestyle.cpp @@ -1362,11 +1362,8 @@ void QPlastiqueStyle::drawPrimitive(PrimitiveElement element, const QStyleOption if (const QStyleOptionFrame *lineEdit = qstyleoption_cast(option)) { // Panel of a line edit inside combo box or spin box is drawn in CC_ComboBox and CC_SpinBox if (widget) { -#ifndef QT_NO_COMBOBOX - if (qobject_cast(widget->parentWidget())) - break; -#endif #ifndef QT_NO_SPINBOX + // Spinbox doesn't need a separate palette for the lineedit if (qobject_cast(widget->parentWidget())) break; #endif diff --git a/src/gui/styles/qwindowsvistastyle.cpp b/src/gui/styles/qwindowsvistastyle.cpp index bed5b09..d6d3f10 100644 --- a/src/gui/styles/qwindowsvistastyle.cpp +++ b/src/gui/styles/qwindowsvistastyle.cpp @@ -588,10 +588,6 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (QAbstractSpinBox *spinbox = qobject_cast(widget->parentWidget())) resolve_mask = spinbox->palette().resolve(); #endif // QT_NO_SPINBOX -#ifndef QT_NO_COMBOBOX - if (QComboBox *combobox = qobject_cast(widget->parentWidget())) - resolve_mask = combobox->palette().resolve(); -#endif // QT_NO_COMBOBOX } if (resolve_mask & (1 << QPalette::Base)) { // Base color is set for this widget, so use it diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 21dd127..b857e94 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -1089,6 +1089,8 @@ void QComboBoxPrivate::updateViewContainerPaletteAndOpacity() container->setPalette(q->palette()); container->setWindowOpacity(1.0); } + if (lineEdit) + lineEdit->setPalette(q->palette()); } /*! diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp index f00f3ef..71dab40 100644 --- a/tests/auto/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/qcombobox/tst_qcombobox.cpp @@ -475,6 +475,18 @@ void tst_QComboBox::setPalette() QVERIFY(((QWidget*)o)->palette() == pal); } } + + testWidget->setEditable(true); + pal.setColor(QPalette::Base, Qt::red); + //Setting it on the lineedit should be separate form the combo + testWidget->lineEdit()->setPalette(pal); + QVERIFY(testWidget->palette() != pal); + QVERIFY(testWidget->lineEdit()->palette() == pal); + pal.setColor(QPalette::Base, Qt::green); + //Setting it on the combo directly should override lineedit + testWidget->setPalette(pal); + QVERIFY(testWidget->palette() == pal); + QVERIFY(testWidget->lineEdit()->palette() == pal); } void tst_QComboBox::sizeAdjustPolicy() -- cgit v0.12