summaryrefslogtreecommitdiffstats
path: root/examples/widgets/widgets/styles
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2020-01-04 15:32:34 +0100
committerLiang Qi <liang.qi@qt.io>2020-01-04 15:32:34 +0100
commita503bf54705d89204007e8f887b668fe5ef519fc (patch)
treeb2d1a452da39450eac78a1aeb1df116a73f64b23 /examples/widgets/widgets/styles
parente65c43fd0ffa57248e7d750570b7deae171a82f5 (diff)
parent1f87fb359fdff14e42662384a9c8a0bcb3837671 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: src/corelib/tools/qvector.h Make QVector(DataPointer dd) public to be able to properly merge 5b4b437b30b320e2cd7c9a566999a39772e5d431 from 5.15 into dev. src/widgets/kernel/qapplication.cpp tests/auto/tools/moc/allmocs_baseline_in.json Done-With: Christian Ehrlicher <ch.ehrlicher@gmx.de> Change-Id: I929ba7c036d570382d0454c2c75f6f0d96ddbc01
Diffstat (limited to 'examples/widgets/widgets/styles')
-rw-r--r--examples/widgets/widgets/styles/main.cpp3
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.cpp1
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.cpp26
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.h4
4 files changed, 30 insertions, 4 deletions
diff --git a/examples/widgets/widgets/styles/main.cpp b/examples/widgets/widgets/styles/main.cpp
index d340719984..471589d3ad 100644
--- a/examples/widgets/widgets/styles/main.cpp
+++ b/examples/widgets/widgets/styles/main.cpp
@@ -50,12 +50,15 @@
#include <QApplication>
+#include "norwegianwoodstyle.h"
#include "widgetgallery.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(styles);
+ QApplication::setStyle(new NorwegianWoodStyle);
+
QApplication app(argc, argv);
WidgetGallery gallery;
gallery.show();
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
index 0f614a2e9a..bbdb626a18 100644
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
@@ -58,6 +58,7 @@
NorwegianWoodStyle::NorwegianWoodStyle() :
QProxyStyle(QStyleFactory::create("windows"))
{
+ setObjectName("NorwegianWood");
}
//! [0]
diff --git a/examples/widgets/widgets/styles/widgetgallery.cpp b/examples/widgets/widgets/styles/widgetgallery.cpp
index 7e1616c6c0..d70c503f53 100644
--- a/examples/widgets/widgets/styles/widgetgallery.cpp
+++ b/examples/widgets/widgets/styles/widgetgallery.cpp
@@ -143,6 +143,7 @@ WidgetGallery::WidgetGallery(QWidget *parent)
setLayout(mainLayout);
setWindowTitle(tr("Styles"));
+ styleChanged();
}
//! [4]
@@ -150,12 +151,10 @@ WidgetGallery::WidgetGallery(QWidget *parent)
void WidgetGallery::changeStyle(const QString &styleName)
//! [5] //! [6]
{
- if (styleName == "NorwegianWood") {
+ if (styleName == "NorwegianWood")
QApplication::setStyle(new NorwegianWoodStyle);
- } else {
+ else
QApplication::setStyle(QStyleFactory::create(styleName));
- }
- changePalette();
}
//! [6]
@@ -170,6 +169,25 @@ void WidgetGallery::changePalette()
}
//! [8]
+void WidgetGallery::changeEvent(QEvent *event)
+{
+ if (event->type() == QEvent::StyleChange)
+ styleChanged();
+}
+
+void WidgetGallery::styleChanged()
+{
+ auto styleName = QApplication::style()->objectName();
+ for (int i = 0; i < styleComboBox->count(); ++i) {
+ if (QString::compare(styleComboBox->itemText(i), styleName, Qt::CaseInsensitive) == 0) {
+ styleComboBox->setCurrentIndex(i);
+ break;
+ }
+ }
+
+ changePalette();
+}
+
//! [9]
void WidgetGallery::advanceProgressBar()
//! [9] //! [10]
diff --git a/examples/widgets/widgets/styles/widgetgallery.h b/examples/widgets/widgets/styles/widgetgallery.h
index 9ee65c21c4..4deee6839a 100644
--- a/examples/widgets/widgets/styles/widgetgallery.h
+++ b/examples/widgets/widgets/styles/widgetgallery.h
@@ -80,8 +80,12 @@ class WidgetGallery : public QDialog
public:
WidgetGallery(QWidget *parent = nullptr);
+protected:
+ void changeEvent(QEvent *) override;
+
private slots:
void changeStyle(const QString &styleName);
+ void styleChanged();
void changePalette();
void advanceProgressBar();