QtBase: Fix painting example arthur background color
authorDavid Schulz <david.schulz@digia.com>
Tue, 27 Nov 2012 09:14:15 +0000 (10:14 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 29 Nov 2012 23:53:07 +0000 (00:53 +0100)
The arthur style set the background color to a bright color
and leave the foregroud color, for example for text, untouched.

If you are using a color theme with bright foregroundcolors on your
system this will result in unreadable text on push- and
radio-buttons.

The function drawControl is now reimplemented and the labels
with text are drawn with an appropriate color.

Change-Id: Ifd7f3a2b1c0305130255009c7733e0966830171a
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
examples/widgets/painting/shared/arthurstyle.cpp
examples/widgets/painting/shared/arthurstyle.h

index 7d56e55..78b48cc 100644 (file)
@@ -311,6 +311,44 @@ void ArthurStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
     return;
 }
 
+void ArthurStyle::drawControl(QStyle::ControlElement element, const QStyleOption *option,
+                              QPainter *painter, const QWidget *widget) const
+{
+    switch (element) {
+    case CE_RadioButtonLabel:
+        if (const QStyleOptionButton *button
+                = qstyleoption_cast<const QStyleOptionButton *>(option)) {
+
+            if (button->text.isEmpty()) {
+                QCommonStyle::drawControl(element, option, painter, widget);
+            } else {
+                painter->save();
+                painter->setPen(Qt::black);
+                painter->drawText(button->rect, Qt::AlignVCenter, button->text);
+                painter->restore();
+            }
+        }
+        break;
+    case CE_PushButtonLabel:
+        if (const QStyleOptionButton *button
+                = qstyleoption_cast<const QStyleOptionButton *>(option)) {
+
+            if (button->text.isEmpty()) {
+                QCommonStyle::drawControl(element, option, painter, widget);
+            } else {
+                painter->save();
+                painter->setPen(Qt::black);
+                painter->drawText(button->rect, Qt::AlignVCenter | Qt::AlignHCenter, button->text);
+                painter->restore();
+            }
+        }
+        break;
+    default:
+        QCommonStyle::drawControl(element, option, painter, widget);
+        break;
+    }
+}
+
 QRect ArthurStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
                                   SubControl subControl, const QWidget *widget) const
 {
index 074437b..9eda158 100644 (file)
@@ -55,8 +55,8 @@ public:
 
     void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                        QPainter *painter, const QWidget *widget = 0) const;
-//     void drawControl(ControlElement element, const QStyleOption *option,
-//                      QPainter *painter, const QWidget *widget) const;
+    void drawControl(ControlElement element, const QStyleOption *option,
+                     QPainter *painter, const QWidget *widget) const;
     void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
                             QPainter *painter, const QWidget *widget) const;
     QSize sizeFromContents(ContentsType type, const QStyleOption *option,
@@ -66,9 +66,6 @@ public:
     QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,
                          SubControl sc, const QWidget *widget) const;
 
-//     SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
-//                                  const QPoint &pos, const QWidget *widget = 0) const;
-
     int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const;
 
     void polish(QPalette &palette);