summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/widgets/doc/src/styles.qdoc21
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.cpp17
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.h6
3 files changed, 26 insertions, 18 deletions
diff --git a/examples/widgets/doc/src/styles.qdoc b/examples/widgets/doc/src/styles.qdoc
index c654a9b958..279332878f 100644
--- a/examples/widgets/doc/src/styles.qdoc
+++ b/examples/widgets/doc/src/styles.qdoc
@@ -37,12 +37,15 @@
A style in Qt is a subclass of QStyle or of one of its
subclasses. Styles perform drawing on behalf of widgets. Qt
provides a whole range of predefined styles, either built into
- the \l QtGui library or found in plugins. Custom styles are
- usually created by subclassing one of Qt's existing style and
- reimplementing a few virtual functions.
+ the \l QtWidgets library or found in plugins. Styles are usually
+ customized by subclassing QProxyStyle and reimplementing a few
+ virtual functions. While QProxyStyle provides a transparent way
+ to customize either a specific style or the appropriate platform's
+ default style, Qt also provides QCommonStyle as a convenient base
+ for full custom style implementations.
In this example, the custom style is called \c NorwegianWoodStyle
- and derives from QWindowsStyle. Its main features are the wooden
+ and derives from QProxyStyle. Its main features are the wooden
textures used for filling most of the widgets and its round
buttons and comboboxes.
@@ -56,7 +59,7 @@
The example consists of the following classes:
\list
- \li \c NorwegianWoodStyle inherits from QWindowsStyle and implements
+ \li \c NorwegianWoodStyle inherits from QProxyStyle and implements
the Norwegian Wood style.
\li \c WidgetGallery is a \c QDialog subclass that shows the most
common widgets and allows the user to switch style
@@ -69,7 +72,7 @@
\snippet widgets/styles/norwegianwoodstyle.h 0
- The public functions are all declared in QStyle (QWindowsStyle's
+ The public functions are all declared in QStyle (QProxyStyle's
grandparent class) and reimplemented here to override the Windows
look and feel. The private functions are helper functions.
@@ -154,7 +157,7 @@
\image styles-disabledwood.png The Norwegian Wood style with disabled widgets
Let's move on to the other functions reimplemented from
- QWindowsStyle:
+ QProxyStyle:
\snippet widgets/styles/norwegianwoodstyle.cpp 3
\snippet widgets/styles/norwegianwoodstyle.cpp 4
@@ -201,13 +204,13 @@
\snippet widgets/styles/norwegianwoodstyle.cpp 10
The \l{QStyle::styleHint()}{styleHint()} function returns some
- hints to widgets or to the base style (in our case QWindowsStyle)
+ hints to widgets or to the base style (in our case QProxyStyle)
about how to draw the widgets. The Windows style returns \c true
for the QStyle::SH_DitherDisabledText hint, resulting in a most
unpleasing visual effect. We override this behavior and return \c
false instead. We also return \c true for the
QStyle::SH_EtchDisabledText hint, meaning that disabled text is
- rendered with an embossed look (as QWindowsStyle does).
+ rendered with an embossed look.
\snippet widgets/styles/norwegianwoodstyle.cpp 11
\snippet widgets/styles/norwegianwoodstyle.cpp 12
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
index b8a677b9fa..9fe3d39be2 100644
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
@@ -42,6 +42,11 @@
#include "norwegianwoodstyle.h"
+NorwegianWoodStyle::NorwegianWoodStyle() :
+ QProxyStyle(QStyleFactory::create("windows"))
+{
+}
+
//! [0]
void NorwegianWoodStyle::polish(QPalette &palette)
{
@@ -112,9 +117,9 @@ int NorwegianWoodStyle::pixelMetric(PixelMetric metric,
case PM_ComboBoxFrameWidth:
return 8;
case PM_ScrollBarExtent:
- return QWindowsStyle::pixelMetric(metric, option, widget) + 4;
+ return QProxyStyle::pixelMetric(metric, option, widget) + 4;
default:
- return QWindowsStyle::pixelMetric(metric, option, widget);
+ return QProxyStyle::pixelMetric(metric, option, widget);
}
}
//! [8]
@@ -131,7 +136,7 @@ int NorwegianWoodStyle::styleHint(StyleHint hint, const QStyleOption *option,
case SH_EtchDisabledText:
return int(true);
default:
- return QWindowsStyle::styleHint(hint, option, widget, returnData);
+ return QProxyStyle::styleHint(hint, option, widget, returnData);
}
}
//! [10]
@@ -256,7 +261,7 @@ void NorwegianWoodStyle::drawPrimitive(PrimitiveElement element,
//! [32] //! [33]
default:
//! [33] //! [34]
- QWindowsStyle::drawPrimitive(element, option, painter, widget);
+ QProxyStyle::drawPrimitive(element, option, painter, widget);
}
}
//! [34]
@@ -284,11 +289,11 @@ void NorwegianWoodStyle::drawControl(ControlElement element,
}
}
}
- QWindowsStyle::drawControl(element, &myButtonOption, painter, widget);
+ QProxyStyle::drawControl(element, &myButtonOption, painter, widget);
}
break;
default:
- QWindowsStyle::drawControl(element, option, painter, widget);
+ QProxyStyle::drawControl(element, option, painter, widget);
}
}
//! [36]
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.h b/examples/widgets/widgets/styles/norwegianwoodstyle.h
index 84ace3b7a8..e8bb0fb096 100644
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.h
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.h
@@ -41,7 +41,7 @@
#ifndef NORWEGIANWOODSTYLE_H
#define NORWEGIANWOODSTYLE_H
-#include <QWindowsStyle>
+#include <QProxyStyle>
#include <QPalette>
QT_BEGIN_NAMESPACE
@@ -49,12 +49,12 @@ class QPainterPath;
QT_END_NAMESPACE
//! [0]
-class NorwegianWoodStyle : public QWindowsStyle
+class NorwegianWoodStyle : public QProxyStyle
{
Q_OBJECT
public:
- NorwegianWoodStyle() {}
+ NorwegianWoodStyle();
void polish(QPalette &palette);
void polish(QWidget *widget);