Add QProxyStyle(QString key) constructor for convenience
The QStyle implementations are becoming private, so the following slightly verbose pattern seems to be now repeated a lot: new QProxyStyle(QStyleFactory::create("windows")) This change adds an alternative, more convenient constructor for this particular use case: new QProxyStyle("windows") Change-Id: I97ded597a0fd3225a6354ebea0abb367237430af Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
This commit is contained in:
parent
4b7276b93f
commit
14dab5b2d7
@ -108,10 +108,9 @@ void QProxyStylePrivate::ensureBaseStyle() const
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs a QProxyStyle object for overriding behavior in \a style
|
||||
or in the current application \l{QStyle}{style} if \a style is 0
|
||||
(default). Normally \a style is 0, because you want to override
|
||||
behavior in the system style.
|
||||
Constructs a QProxyStyle object for overriding behavior in the
|
||||
specified base \a style, or in the current \l{QApplication::style}
|
||||
{application style} if base \a style is not specified.
|
||||
|
||||
Ownership of \a style is transferred to QProxyStyle.
|
||||
*/
|
||||
@ -126,6 +125,26 @@ QProxyStyle::QProxyStyle(QStyle *style) :
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs a QProxyStyle object for overriding behavior in
|
||||
the base style specified by style \a key, or in the current
|
||||
\l{QApplication::style}{application style} if the specified
|
||||
style \a key is unrecognized.
|
||||
|
||||
\sa QStyleFactory::create()
|
||||
*/
|
||||
QProxyStyle::QProxyStyle(const QString &key) :
|
||||
QCommonStyle(*new QProxyStylePrivate())
|
||||
{
|
||||
Q_D(QProxyStyle);
|
||||
QStyle *style = QStyleFactory::create(key);
|
||||
if (style) {
|
||||
d->baseStyle = style;
|
||||
style->setProxy(this);
|
||||
style->setParent(this); // Take ownership
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Destroys the QProxyStyle object.
|
||||
*/
|
||||
|
@ -55,7 +55,8 @@ class Q_WIDGETS_EXPORT QProxyStyle : public QCommonStyle
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QProxyStyle(QStyle *baseStyle = 0);
|
||||
QProxyStyle(QStyle *style = 0);
|
||||
QProxyStyle(const QString &key);
|
||||
~QProxyStyle();
|
||||
|
||||
QStyle *baseStyle() const;
|
||||
|
@ -234,7 +234,10 @@ void tst_QStyle::testProxyStyle()
|
||||
QVERIFY(proxyStyle->baseStyle());
|
||||
qApp->setStyle(proxyStyle);
|
||||
|
||||
QProxyStyle doubleProxy(new QProxyStyle(QStyleFactory::create("Windows")));
|
||||
QProxyStyle* baseStyle = new QProxyStyle("Windows");
|
||||
QCOMPARE(baseStyle->baseStyle()->objectName(), style->objectName());
|
||||
|
||||
QProxyStyle doubleProxy(baseStyle);
|
||||
QVERIFY(testAllFunctions(&doubleProxy));
|
||||
|
||||
CustomProxy customStyle;
|
||||
@ -775,7 +778,7 @@ void tst_QStyle::testDrawingShortcuts()
|
||||
|
||||
class FrameTestStyle : public QProxyStyle {
|
||||
public:
|
||||
FrameTestStyle() : QProxyStyle(QStyleFactory::create("Windows")) { }
|
||||
FrameTestStyle() : QProxyStyle("Windows") { }
|
||||
int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const {
|
||||
if (hint == QStyle::SH_ScrollView_FrameOnlyAroundContents)
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user