summaryrefslogtreecommitdiffstats
path: root/examples/widgets/widgets/styles/widgetgallery.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/widgets/styles/widgetgallery.cpp')
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.cpp26
1 files changed, 22 insertions, 4 deletions
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]