diff options
Diffstat (limited to 'examples')
21 files changed, 48 insertions, 365 deletions
diff --git a/examples/corelib/platform/androidnotifier/androidnotifier.pro b/examples/corelib/platform/androidnotifier/androidnotifier.pro index 6ac4c69eb3..7e5b845e10 100644 --- a/examples/corelib/platform/androidnotifier/androidnotifier.pro +++ b/examples/corelib/platform/androidnotifier/androidnotifier.pro @@ -1,5 +1,4 @@ -QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +QT += core gui widgets QT += core-private # For Notification permission request SOURCES += \ diff --git a/examples/opengl/cube/fshader.glsl b/examples/opengl/cube/fshader.glsl index 18068cf0e6..0c056b6165 100644 --- a/examples/opengl/cube/fshader.glsl +++ b/examples/opengl/cube/fshader.glsl @@ -1,3 +1,5 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifdef GL_ES // Set default precision to medium precision mediump int; diff --git a/examples/opengl/cube/vshader.glsl b/examples/opengl/cube/vshader.glsl index cfdc061852..ac57d96285 100644 --- a/examples/opengl/cube/vshader.glsl +++ b/examples/opengl/cube/vshader.glsl @@ -1,3 +1,5 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifdef GL_ES // Set default precision to medium precision mediump int; diff --git a/examples/widgets/animation/CMakeLists.txt b/examples/widgets/animation/CMakeLists.txt index d9a18bb866..ed8ee0558c 100644 --- a/examples/widgets/animation/CMakeLists.txt +++ b/examples/widgets/animation/CMakeLists.txt @@ -1 +1,3 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause qt_internal_add_example(easing) diff --git a/examples/widgets/desktop/CMakeLists.txt b/examples/widgets/desktop/CMakeLists.txt index 169fa9ffac..0f4eda12aa 100644 --- a/examples/widgets/desktop/CMakeLists.txt +++ b/examples/widgets/desktop/CMakeLists.txt @@ -1,2 +1,4 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause qt_internal_add_example(screenshot) qt_internal_add_example(systray) diff --git a/examples/widgets/doc/src/coloreditorfactory.qdoc b/examples/widgets/doc/src/coloreditorfactory.qdoc deleted file mode 100644 index f43a7eb95c..0000000000 --- a/examples/widgets/doc/src/coloreditorfactory.qdoc +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example itemviews/coloreditorfactory - \title Color Editor Factory Example - \examplecategory {User Interface Components} - \ingroup examples-itemviews - \brief This example shows how to create an editor that can be used by - a QStyledItemDelegate. - - \image coloreditorfactoryimage.png - - When editing data in a QListView, QTableView, or QTreeView, - editors are created and displayed by a \l{Delegate - Classes}{delegate}. QStyledItemDelegate, which is the default delegate - used by Qt's \l{View Classes}{item views}, uses a - QItemEditorFactory to create editors for it. A unique instance - provided by QItemEditorFactory is by default installed on all - item delegates. - - An item editor factory contains a collection of - QItemEditorCreatorBase instances, which are specialized factories - that produce editors for one particular QVariant data type (all - models in Qt store their data in \l{QVariant}s). An editor can be any - Qt or custom widget. - - In this example, we will create an editor (implemented in the \c - ColorListEditor class) that can edit the QColor data type and be - used by \l{QStyledItemDelegate}s. We do this by creating a new - QItemEditorCreatorBase that produces \c ColorListEditors and - register it with a new factory, which we set as the default editor - item factory (the unique factory instance). To test our editor, we - have implemented the \c Window class, which displays a - QTableWidget in which \l{QColor}s can be edited. - - \section1 Window Class Implementation - - In the Window class, we create the item editor creator - base for our color editor and add it to the default factory. - We also create a QTableWidget in which our editor can be - tested. It is filled with some data and displayed in a window. - - We take a closer look at the constructor: - - \snippet itemviews/coloreditorfactory/window.cpp 0 - - The QStandardItemEditorCreator is a convenience class that - inherits QItemEditorCreatorBase. Its constructor takes a template - class, of which instances are returned from - \l{QItemEditorCreatorBase::}{createWidget()}. The creator uses a - constructor that takes a QWidget as its only parameter; the - template class must provide this. This way, there is no need to - subclass QStandardItemEditorCreator. - - After the new factory has been set, all standard item delegates - will use it (i.e, also delegates that were created before the new - default factory was set). - - The \c createGUI() function sets up the table and fills it - with data. - - \section1 ColorListEditor Definition - - The ColorListEditor inherits QComboBox and lets the user - select a QColor from its popup list. - - \snippet itemviews/coloreditorfactory/colorlisteditor.h 0 - - QStyledItemDelegate manages the interaction between the editor and - the model, i.e., it retrieves data to edit from the model and - store data from the editor in the model. The data that is edited - by an editor is stored in the editor's user data property, and the - delegate uses Qt's \l{Qt's Property System}{property system} to - access it by name. We declare our user data property with the - Q_PROPERTY macro. The property is set to be the user type with the - USER keyword. - - \section1 ColorListEditor Implementation - - The constructor of \c ColorListEditor simply calls \c - populateList(), which we will look at later. We move on to the - \c color() function: - - \snippet itemviews/coloreditorfactory/colorlisteditor.cpp 0 - - We return the data that is selected in the combobox. The data - is stored in the Qt::DecorationRole as the color is then also - displayed in the popup list (as shown in the image above). - - \snippet itemviews/coloreditorfactory/colorlisteditor.cpp 1 - - The \c findData() function searches the items in the combobox - and returns the index of the item that has \c color in the - Qt::Decoration role. - - \snippet itemviews/coloreditorfactory/colorlisteditor.cpp 2 - - Qt knows some predefined colors by name. We simply loop - through these to fill our editor with items. - - \section1 Further Customization of Item View Editors - - You can customize Qt's \l{Model/View Programming}{model view - framework} in many ways. The procedure shown in this example is - usually sufficient to provide custom editors. Further - customization is achieved by subclassing QItemEditorFactory - and QItemEditorCreatorBase. It is also possible to subclass - QStyledItemDelegate if you don't wish to use a factory at all. - - Possible suggestions are: - - \list - \li If the editor widget has no user property defined, the delegate - asks the factory for the property name, which it in turn - asks the item editor creator for. In this case, you can use - the QItemEditorCreator class, which takes the property - name to use for editing as a constructor argument. - \li If the editor requires other constructors or other - initialization than provided by QItemEditorCreatorBase, you - must reimplement - QItemEditorCreatorBase::createWidget(). - \li You could also subclass QItemEditorFactory if you only want - to provide editors for certain kinds of data or use another - method of creating the editors than using creator bases. - \endlist - - In this example, we use a standard QVariant data type. You can - also use custom types. In the \l{Star Delegate Example}, we - show how to store a custom data type in a QVariant and paint - and edit it in a class that inherits QStyledItemDelegate. -*/ diff --git a/examples/widgets/doc/src/simpletreemodel.qdoc b/examples/widgets/doc/src/simpletreemodel.qdoc index aa12a9585f..d8e5a6faa8 100644 --- a/examples/widgets/doc/src/simpletreemodel.qdoc +++ b/examples/widgets/doc/src/simpletreemodel.qdoc @@ -295,14 +295,14 @@ We begin with a text file in the following format: \code - Getting Started How to familiarize yourself with Qt Designer - Launching Designer Running the Qt Designer application - The User Interface How to interact with Qt Designer + Getting Started How to familiarize yourself with Qt Widgets Designer + Launching Designer Running the Qt Widgets Designer application + The User Interface How to interact with Qt Widgets Designer \endcode \dots \code Connection Editing Mode Connecting widgets together with signals and slots - Connecting Objects Making connections in Qt Designer + Connecting Objects Making connections in Qt Widgets Designer Editing Connections Changing existing connections \endcode 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); diff --git a/examples/widgets/itemviews/CMakeLists.txt b/examples/widgets/itemviews/CMakeLists.txt index 0c2912178f..e80d90160b 100644 --- a/examples/widgets/itemviews/CMakeLists.txt +++ b/examples/widgets/itemviews/CMakeLists.txt @@ -3,7 +3,6 @@ qt_internal_add_example(addressbook) qt_internal_add_example(basicsortfiltermodel) -qt_internal_add_example(coloreditorfactory) qt_internal_add_example(combowidgetmapper) qt_internal_add_example(customsortfiltermodel) qt_internal_add_example(editabletreemodel) diff --git a/examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt b/examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt deleted file mode 100644 index 5dbc780027..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(coloreditorfactory LANGUAGES CXX) - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) - -qt_standard_project_setup() - -qt_add_executable(coloreditorfactory - colorlisteditor.cpp colorlisteditor.h - main.cpp - window.cpp window.h -) - -set_target_properties(coloreditorfactory PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(coloreditorfactory PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets -) - -install(TARGETS coloreditorfactory - BUNDLE DESTINATION . - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} -) - -qt_generate_deploy_app_script( - TARGET coloreditorfactory - OUTPUT_SCRIPT deploy_script - NO_UNSUPPORTED_PLATFORM_ERROR -) -install(SCRIPT ${deploy_script}) diff --git a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro b/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro deleted file mode 100644 index 2d16ab5e2b..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro +++ /dev/null @@ -1,12 +0,0 @@ -QT += widgets -requires(qtConfig(combobox)) - -HEADERS = colorlisteditor.h \ - window.h -SOURCES = colorlisteditor.cpp \ - window.cpp \ - main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/coloreditorfactory -INSTALLS += target diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp deleted file mode 100644 index 44ce168c93..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "colorlisteditor.h" - -#include <QtWidgets> - -ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget) -{ - populateList(); -} - -//! [0] -QColor ColorListEditor::color() const -{ - return qvariant_cast<QColor>(itemData(currentIndex(), Qt::DecorationRole)); -} -//! [0] - -//! [1] -void ColorListEditor::setColor(const QColor &color) -{ - setCurrentIndex(findData(color, Qt::DecorationRole)); -} -//! [1] - -//! [2] -void ColorListEditor::populateList() -{ - const QStringList colorNames = QColor::colorNames(); - - for (int i = 0; i < colorNames.size(); ++i) { - QColor color(colorNames[i]); - - insertItem(i, colorNames[i]); - setItemData(i, color, Qt::DecorationRole); - } -} -//! [2] diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h deleted file mode 100644 index 8dfa9d9f05..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef COLORLISTEDITOR_H -#define COLORLISTEDITOR_H - -#include <QComboBox> - -QT_BEGIN_NAMESPACE -class QColor; -class QWidget; -QT_END_NAMESPACE - -//! [0] -class ColorListEditor : public QComboBox -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor USER true) - -public: - ColorListEditor(QWidget *widget = nullptr); - -public: - QColor color() const; - void setColor(const QColor &color); - -private: - void populateList(); -}; -//! [0] - -#endif diff --git a/examples/widgets/itemviews/coloreditorfactory/main.cpp b/examples/widgets/itemviews/coloreditorfactory/main.cpp deleted file mode 100644 index c4339e22c1..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/main.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QtWidgets> - -#include "window.h" - -int main(int argv, char **args) -{ - QApplication app(argv, args); - - Window window; - window.show(); - - return app.exec(); -} diff --git a/examples/widgets/itemviews/coloreditorfactory/window.cpp b/examples/widgets/itemviews/coloreditorfactory/window.cpp deleted file mode 100644 index 31c8c1ae13..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/window.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "window.h" -#include "colorlisteditor.h" - -#include <QtWidgets> - -//! [0] -Window::Window() -{ - QItemEditorFactory *factory = new QItemEditorFactory; - - QItemEditorCreatorBase *colorListCreator = - new QStandardItemEditorCreator<ColorListEditor>(); - - factory->registerEditor(QMetaType::QColor, colorListCreator); - - QItemEditorFactory::setDefaultFactory(factory); - - createGUI(); -} -//! [0] - -void Window::createGUI() -{ - const QList<QPair<QString, QColor>> list = { { tr("Alice"), QColor("aliceblue") }, - { tr("Neptun"), QColor("aquamarine") }, - { tr("Ferdinand"), QColor("springgreen") } }; - - QTableWidget *table = new QTableWidget(3, 2); - table->setHorizontalHeaderLabels({ tr("Name"), tr("Hair Color") }); - table->verticalHeader()->setVisible(false); - table->resize(150, 50); - - for (int i = 0; i < 3; ++i) { - const QPair<QString, QColor> &pair = list.at(i); - - QTableWidgetItem *nameItem = new QTableWidgetItem(pair.first); - QTableWidgetItem *colorItem = new QTableWidgetItem; - colorItem->setData(Qt::DisplayRole, pair.second); - - table->setItem(i, 0, nameItem); - table->setItem(i, 1, colorItem); - } - table->resizeColumnToContents(0); - table->horizontalHeader()->setStretchLastSection(true); - - QGridLayout *layout = new QGridLayout; - layout->addWidget(table, 0, 0); - - setLayout(layout); - - setWindowTitle(tr("Color Editor Factory")); -} diff --git a/examples/widgets/itemviews/coloreditorfactory/window.h b/examples/widgets/itemviews/coloreditorfactory/window.h deleted file mode 100644 index 4130b2d4ac..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/window.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef WINDOW_H -#define WINDOW_H - -#include <QWidget> - -class Window : public QWidget -{ - Q_OBJECT - -public: - Window(); - -private: - void createGUI(); -}; - -#endif diff --git a/examples/widgets/itemviews/editabletreemodel/default.txt b/examples/widgets/itemviews/editabletreemodel/default.txt index 2b2fb579ae..c3ea35257c 100644 --- a/examples/widgets/itemviews/editabletreemodel/default.txt +++ b/examples/widgets/itemviews/editabletreemodel/default.txt @@ -1,6 +1,6 @@ -Getting Started How to familiarize yourself with Qt Designer - Launching Designer Running the Qt Designer application - The User Interface How to interact with Qt Designer +Getting Started How to familiarize yourself with Qt Widgets Designer + Launching Designer Running the Qt Widgets Designer application + The User Interface How to interact with Qt Widgets Designer Designing a Component Creating a GUI for your application Creating a Dialog How to create a dialog @@ -16,7 +16,7 @@ Using a Component in Your Application Generating code from forms A Dialog Without Auto-Connect How to connect widgets without a naming scheme A Dialog With Auto-Connect Using automatic connections -Form Editing Mode How to edit a form in Qt Designer +Form Editing Mode How to edit a form in Qt Widgets Designer Managing Forms Loading and saving forms Editing a Form Basic editing techniques The Property Editor Changing widget properties @@ -36,5 +36,5 @@ Using Containers How to group widgets together Toolbox Widgets QToolBox Connection Editing Mode Connecting widgets together with signals and slots - Connecting Objects Making connections in Qt Designer + Connecting Objects Making connections in Qt Widgets Designer Editing Connections Changing existing connections diff --git a/examples/widgets/itemviews/itemviews.pro b/examples/widgets/itemviews/itemviews.pro index 92997782a2..db06874ba5 100644 --- a/examples/widgets/itemviews/itemviews.pro +++ b/examples/widgets/itemviews/itemviews.pro @@ -1,7 +1,6 @@ TEMPLATE = subdirs SUBDIRS = addressbook \ basicsortfiltermodel \ - coloreditorfactory \ combowidgetmapper \ customsortfiltermodel \ editabletreemodel \ diff --git a/examples/widgets/itemviews/simpletreemodel/default.txt b/examples/widgets/itemviews/simpletreemodel/default.txt index 2b2fb579ae..c3ea35257c 100644 --- a/examples/widgets/itemviews/simpletreemodel/default.txt +++ b/examples/widgets/itemviews/simpletreemodel/default.txt @@ -1,6 +1,6 @@ -Getting Started How to familiarize yourself with Qt Designer - Launching Designer Running the Qt Designer application - The User Interface How to interact with Qt Designer +Getting Started How to familiarize yourself with Qt Widgets Designer + Launching Designer Running the Qt Widgets Designer application + The User Interface How to interact with Qt Widgets Designer Designing a Component Creating a GUI for your application Creating a Dialog How to create a dialog @@ -16,7 +16,7 @@ Using a Component in Your Application Generating code from forms A Dialog Without Auto-Connect How to connect widgets without a naming scheme A Dialog With Auto-Connect Using automatic connections -Form Editing Mode How to edit a form in Qt Designer +Form Editing Mode How to edit a form in Qt Widgets Designer Managing Forms Loading and saving forms Editing a Form Basic editing techniques The Property Editor Changing widget properties @@ -36,5 +36,5 @@ Using Containers How to group widgets together Toolbox Widgets QToolBox Connection Editing Mode Connecting widgets together with signals and slots - Connecting Objects Making connections in Qt Designer + Connecting Objects Making connections in Qt Widgets Designer Editing Connections Changing existing connections diff --git a/examples/widgets/widgets/shortcuteditor/CMakeLists.txt b/examples/widgets/widgets/shortcuteditor/CMakeLists.txt index 5d1c4a8dc1..d10248fbd7 100644 --- a/examples/widgets/widgets/shortcuteditor/CMakeLists.txt +++ b/examples/widgets/widgets/shortcuteditor/CMakeLists.txt @@ -1,3 +1,5 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(shortcuteditor LANGUAGES CXX) |