summaryrefslogtreecommitdiffstats
path: root/examples/widgets/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/gallery')
-rw-r--r--examples/widgets/gallery/CMakeLists.txt31
-rw-r--r--examples/widgets/gallery/main.cpp1
-rw-r--r--examples/widgets/gallery/widgetgallery.cpp24
3 files changed, 39 insertions, 17 deletions
diff --git a/examples/widgets/gallery/CMakeLists.txt b/examples/widgets/gallery/CMakeLists.txt
index 02788419fd..e0c87afb0b 100644
--- a/examples/widgets/gallery/CMakeLists.txt
+++ b/examples/widgets/gallery/CMakeLists.txt
@@ -4,16 +4,10 @@
cmake_minimum_required(VERSION 3.16)
project(gallery LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/gallery")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
+qt_standard_project_setup()
+
qt_add_executable(gallery
main.cpp
widgetgallery.cpp widgetgallery.h
@@ -24,14 +18,21 @@ set_target_properties(gallery PROPERTIES
MACOSX_BUNDLE TRUE
)
-target_link_libraries(gallery PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Widgets
+target_link_libraries(gallery PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Widgets
)
install(TARGETS gallery
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET gallery
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/gallery/main.cpp b/examples/widgets/gallery/main.cpp
index cfac821209..2677b3708c 100644
--- a/examples/widgets/gallery/main.cpp
+++ b/examples/widgets/gallery/main.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
+#include <QStyleHints>
#include "widgetgallery.h"
diff --git a/examples/widgets/gallery/widgetgallery.cpp b/examples/widgets/gallery/widgetgallery.cpp
index 2de46419d9..d38dcbd5e8 100644
--- a/examples/widgets/gallery/widgetgallery.cpp
+++ b/examples/widgets/gallery/widgetgallery.cpp
@@ -26,6 +26,7 @@
#include <QSpinBox>
#include <QStandardItemModel>
#include <QStyle>
+#include <QStyleHints>
#include <QStyleFactory>
#include <QTextBrowser>
#include <QTreeView>
@@ -135,6 +136,21 @@ WidgetGallery::WidgetGallery(QWidget *parent)
auto styleLabel = createWidget1<QLabel>(tr("&Style:"), "styleLabel");
styleLabel->setBuddy(styleComboBox);
+ auto colorSchemeComboBox = createWidget<QComboBox>("colorSchemeComboBox");
+ colorSchemeComboBox->addItem(tr("Auto"));
+ colorSchemeComboBox->addItem(tr("Light"));
+ colorSchemeComboBox->addItem(tr("Dark"));
+ // override the color scheme to dark
+ qApp->styleHints()->setColorScheme(Qt::ColorScheme::Dark);
+ colorSchemeComboBox->setCurrentIndex(2);
+
+ auto colorSchemeLabel = createWidget1<QLabel>(tr("&Color Scheme:"), "colorSchemeLabel");
+ colorSchemeLabel->setBuddy(colorSchemeComboBox);
+
+ connect(colorSchemeComboBox, &QComboBox::currentIndexChanged, this, [](int index){
+ QGuiApplication::styleHints()->setColorScheme(static_cast<Qt::ColorScheme>(index));
+ });
+
auto helpLabel = createWidget1<QLabel>(tr("Press F1 over a widget to see Documentation"), "helpLabel");
auto disableWidgetsCheckBox = createWidget1<QCheckBox>(tr("&Disable widgets"), "disableWidgetsCheckBox");
@@ -156,8 +172,12 @@ WidgetGallery::WidgetGallery(QWidget *parent)
simpleInputWidgetsGroupBox, &QWidget::setDisabled);
auto topLayout = new QHBoxLayout;
- topLayout->addWidget(styleLabel);
- topLayout->addWidget(styleComboBox);
+ auto appearanceLayout = new QGridLayout;
+ appearanceLayout->addWidget(styleLabel, 0, 0);
+ appearanceLayout->addWidget(styleComboBox, 0, 1);
+ appearanceLayout->addWidget(colorSchemeLabel, 1, 0);
+ appearanceLayout->addWidget(colorSchemeComboBox, 1, 1);
+ topLayout->addLayout(appearanceLayout);
topLayout->addStretch(1);
topLayout->addWidget(helpLabel);
topLayout->addStretch(1);