diff options
author | Amir Masoud Abdol <amirmasoudabdol@icloud.com> | 2022-12-08 14:56:15 +0100 |
---|---|---|
committer | Amir Masoud Abdol <amirmasoudabdol@icloud.com> | 2023-01-18 14:47:12 +0100 |
commit | 7fe2537ce20ebf887d71fe0d0d0fb14b429d68be (patch) | |
tree | e46007589c9ea026769b0ffe3300b8a964ecc119 /examples/widgets/tools/styleplugin | |
parent | b171abe69533a83c5b6fea51807da3ad45a1d3f3 (diff) |
Fix Style Plugin Example, and add some CMake Docs
A few things:
- Improved the documentation by adding a CMake section, briefly
describing the process of adding the plugin, and placing it where it
should be.
- Write a note about the case where the style may be overwritten at
launch, and how to set the a new style using a CLI
- Improved the CMake build such that it creates the App Bundle
correctly, and also works without an App Bundle as well.
- Changed the example, and plugin such that now instead of a QPushButton
we have a QTextEdit, and change the text color.
- Replaced the application screenshot
Fixes: QTBUG-107842
Fixes: QTBUG-109227
Change-Id: I161a91b27df016ff6230fac3871b79d2dfbdf18a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'examples/widgets/tools/styleplugin')
5 files changed, 44 insertions, 11 deletions
diff --git a/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt b/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt index 41df10c578..b82d3ab065 100644 --- a/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt +++ b/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt @@ -1,15 +1,33 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause +#! [0] qt_add_plugin(simplestyleplugin CLASS_NAME SimpleStylePlugin simplestyle.cpp simplestyle.h simplestyleplugin.cpp simplestyleplugin.h ) +#! [0] -set_target_properties(simplestyleplugin PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/stylewindow/styles" -) +if(QT_FEATURE_debug AND APPLE) + set_property(simplestyleplugin + APPEND_STRING PROPERTY OUTPUT_NAME "_debug") +endif() + +get_target_property(is_bundle styleplugin MACOSX_BUNDLE) +if(APPLE AND is_bundle) +#! [1] + set_target_properties(simplestyleplugin PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "$<TARGET_BUNDLE_CONTENT_DIR:styleplugin>/PlugIns/styles" + ) +#! [1] +else() +#! [2] + set_target_properties(simplestyleplugin PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "$<TARGET_FILE_DIR:styleplugin>/styles" + ) +#! [2] +endif() target_link_libraries(simplestyleplugin PRIVATE Qt6::Core diff --git a/examples/widgets/tools/styleplugin/plugin/plugin.pro b/examples/widgets/tools/styleplugin/plugin/plugin.pro index 35184fc82a..5ab00016ca 100644 --- a/examples/widgets/tools/styleplugin/plugin/plugin.pro +++ b/examples/widgets/tools/styleplugin/plugin/plugin.pro @@ -12,7 +12,17 @@ win32 { CONFIG(debug, release|debug):DESTDIR = ../debug/styles/ CONFIG(release, release|debug):DESTDIR = ../release/styles/ } else { - DESTDIR = ../styles/ + macos { + # The non-app-bundle case is not supported with qmake, because + # the plugin project cannot know whether the app is built + # as a bundle or not. + DESTDIR = ../styleplugin.app/Contents/PlugIns/styles/ + contains(QT_CONFIG, debug) { + TARGET = $$join(TARGET,,,_debug) + } + } else { + DESTDIR = ../styles/ + } } EXAMPLE_FILES += simplestyle.json diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp b/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp index 93bea72bcd..fa60d50140 100644 --- a/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp +++ b/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp @@ -5,5 +5,5 @@ void SimpleStyle::polish(QPalette &palette) { - palette.setBrush(QPalette::Button, Qt::red); + palette.setBrush(QPalette::Text, Qt::red); } diff --git a/examples/widgets/tools/styleplugin/stylewindow/main.cpp b/examples/widgets/tools/styleplugin/stylewindow/main.cpp index 0b4ca6320f..0b0a295410 100644 --- a/examples/widgets/tools/styleplugin/stylewindow/main.cpp +++ b/examples/widgets/tools/styleplugin/stylewindow/main.cpp @@ -10,10 +10,15 @@ int main(int argv, char *args[]) { QApplication app(argv, args); - QApplication::setStyle(QStyleFactory::create("simplestyle")); + + QStyle *style = QStyleFactory::create("simplestyle"); + if (!style) + qFatal("Cannot load the 'simplestyle' plugin."); + + QApplication::setStyle(style); StyleWindow window; - window.resize(200, 50); + window.resize(350, 50); window.show(); return app.exec(); diff --git a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp b/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp index fd449057e6..9268666c21 100644 --- a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp +++ b/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp @@ -3,18 +3,18 @@ #include <QGridLayout> #include <QGroupBox> -#include <QPushButton> +#include <QTextEdit> #include "stylewindow.h" StyleWindow::StyleWindow() { - QPushButton *styledButton = new QPushButton(tr("Big Red Button")); + QTextEdit *styledTextEdit = new QTextEdit(tr("The quick brown fox jumps over the lazy dog")); QGridLayout *layout = new QGridLayout; - layout->addWidget(styledButton); + layout->addWidget(styledTextEdit); - QGroupBox *styleBox = new QGroupBox(tr("A simple style button")); + QGroupBox *styleBox = new QGroupBox(tr("A simple styled text edit")); styleBox->setLayout(layout); QGridLayout *outerLayout = new QGridLayout; |