summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/corelib/CMakeLists.txt4
-rw-r--r--examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp6
-rw-r--r--examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h2
-rw-r--r--examples/corelib/bindableproperties/bindablesubscription/bindableuser.h11
-rw-r--r--examples/corelib/bindableproperties/bindablesubscription/main.cpp9
-rw-r--r--examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc32
-rw-r--r--examples/corelib/bindableproperties/subscription/main.cpp9
-rw-r--r--examples/corelib/bindableproperties/subscription/subscription.cpp6
-rw-r--r--examples/corelib/bindableproperties/subscription/subscription.h2
-rw-r--r--examples/corelib/bindableproperties/subscription/user.h13
-rw-r--r--examples/corelib/serialization/savegame/character.cpp6
-rw-r--r--examples/corelib/serialization/savegame/character.h6
-rw-r--r--examples/corelib/serialization/savegame/game.cpp4
-rw-r--r--examples/corelib/serialization/savegame/game.h6
-rw-r--r--examples/corelib/serialization/savegame/level.cpp4
-rw-r--r--examples/corelib/serialization/savegame/level.h6
-rw-r--r--examples/corelib/serialization/savegame/main.cpp3
-rw-r--r--examples/corelib/threads/doc/src/mandelbrot.qdoc10
-rw-r--r--examples/dbus/chat/chat.pro2
-rw-r--r--examples/dbus/remotecontrolledcar/car/car.pro2
-rw-r--r--examples/network/doc/src/blockingfortuneclient.qdoc2
-rw-r--r--examples/network/doc/src/fortuneserver.qdoc2
-rw-r--r--examples/opengl/hellowindow/hellowindow.h5
-rw-r--r--examples/opengl/openglwindow/openglwindow.h4
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.h5
-rw-r--r--examples/qpa/windows/window.h5
-rw-r--r--examples/vulkan/hellovulkantexture/hellovulkantexture.h5
-rw-r--r--examples/vulkan/hellovulkanwidget/hellovulkanwidget.h5
-rw-r--r--examples/vulkan/hellovulkanwindow/hellovulkanwindow.h5
-rw-r--r--examples/vulkan/shared/trianglerenderer.h5
-rw-r--r--examples/widgets/animation/easing/animation.h4
-rw-r--r--examples/widgets/animation/easing/window.cpp2
-rw-r--r--examples/widgets/animation/easing/window.h5
-rw-r--r--examples/widgets/doc/src/tooltips.qdoc16
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.h5
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.h5
-rw-r--r--examples/widgets/layouts/basiclayouts/dialog.cpp19
-rw-r--r--examples/widgets/painting/composition/composition.cpp10
-rw-r--r--examples/widgets/painting/composition/composition.h1
-rw-r--r--examples/widgets/painting/shared/fbopaintdevice.cpp17
-rw-r--r--examples/widgets/painting/shared/fbopaintdevice.h2
-rw-r--r--examples/widgets/tools/echoplugin/CMakeLists.txt4
-rw-r--r--examples/widgets/tools/plugandpaint/CMakeLists.txt4
-rw-r--r--examples/widgets/tools/styleplugin/CMakeLists.txt4
-rw-r--r--examples/widgets/widgets/groupbox/window.cpp4
-rw-r--r--examples/widgets/widgets/sliders/window.cpp41
-rw-r--r--examples/widgets/widgets/sliders/window.h4
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.cpp39
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.h5
-rw-r--r--examples/widgets/widgets/validators/validatorwidget.h5
-rw-r--r--examples/widgets/widgets/windowflags/previewwindow.cpp2
51 files changed, 260 insertions, 124 deletions
diff --git a/examples/corelib/CMakeLists.txt b/examples/corelib/CMakeLists.txt
index 30e2c8cd1f..0a155606e5 100644
--- a/examples/corelib/CMakeLists.txt
+++ b/examples/corelib/CMakeLists.txt
@@ -1,6 +1,5 @@
# Generated from corelib.pro.
-add_subdirectory(bindableproperties)
add_subdirectory(ipc)
add_subdirectory(mimetypes)
add_subdirectory(serialization)
@@ -9,3 +8,6 @@ add_subdirectory(platform)
if(QT_FEATURE_thread)
add_subdirectory(threads)
endif()
+if(QT_FEATURE_widgets)
+ add_subdirectory(bindableproperties)
+endif()
diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp
index 14b28b3fae..e9c57a2d29 100644
--- a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp
+++ b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp
@@ -60,7 +60,7 @@ BindableSubscription::BindableSubscription(BindableUser *user) : m_user(user)
m_price.setBinding([this] { return qRound(calculateDiscount() * m_duration * basePrice()); });
m_isValid.setBinding([this] {
- return m_user->country() != BindableUser::None && m_user->age() > 12;
+ return m_user->country() != BindableUser::Country::AnyCountry && m_user->age() > 12;
});
}
@@ -91,8 +91,8 @@ double BindableSubscription::calculateDiscount() const
int BindableSubscription::basePrice() const
{
- if (m_user->country() == BindableUser::None)
+ if (m_user->country() == BindableUser::Country::AnyCountry)
return 0;
- return (m_user->country() == BindableUser::Norway) ? 100 : 80;
+ return (m_user->country() == BindableUser::Country::Norway) ? 100 : 80;
}
diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h
index 763864d627..5fab4bc91f 100644
--- a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h
+++ b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h
@@ -61,7 +61,7 @@ class BindableUser;
class BindableSubscription
{
public:
- enum Duration { Monthly = 1, Quarterly = 4, Yearly = 12 };
+ enum Duration { Monthly = 1, Quarterly = 3, Yearly = 12 };
BindableSubscription(BindableUser *user);
BindableSubscription(const BindableSubscription &) = delete;
diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h b/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h
index 65541e6ac1..d2ab4a2d42 100644
--- a/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h
+++ b/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h
@@ -51,6 +51,7 @@
#ifndef BINDABLEUSER_H
#define BINDABLEUSER_H
+#include <QLocale>
#include <QProperty>
//! [bindable-user-class]
@@ -58,13 +59,9 @@
class BindableUser
{
public:
- enum Country {
- None,
- Finland,
- Germany,
- Norway,
- };
+ using Country = QLocale::Territory;
+public:
BindableUser() = default;
BindableUser(const BindableUser &) = delete;
@@ -77,7 +74,7 @@ public:
QBindable<int> bindableAge() { return &m_age; }
private:
- QProperty<Country> m_country { None };
+ QProperty<Country> m_country { QLocale::AnyTerritory };
QProperty<int> m_age { 0 };
};
diff --git a/examples/corelib/bindableproperties/bindablesubscription/main.cpp b/examples/corelib/bindableproperties/bindablesubscription/main.cpp
index df935679ad..86f7149648 100644
--- a/examples/corelib/bindableproperties/bindablesubscription/main.cpp
+++ b/examples/corelib/bindableproperties/bindablesubscription/main.cpp
@@ -84,15 +84,15 @@ int main(int argc, char *argv[])
// Initialize user data
QPushButton *germany = w.findChild<QPushButton *>("btnGermany");
QObject::connect(germany, &QPushButton::clicked, [&] {
- user.setCountry(BindableUser::Germany);
+ user.setCountry(BindableUser::Country::Germany);
});
QPushButton *finland = w.findChild<QPushButton *>("btnFinland");
QObject::connect(finland, &QPushButton::clicked, [&] {
- user.setCountry(BindableUser::Finland);
+ user.setCountry(BindableUser::Country::Finland);
});
QPushButton *norway = w.findChild<QPushButton *>("btnNorway");
QObject::connect(norway, &QPushButton::clicked, [&] {
- user.setCountry(BindableUser::Norway);
+ user.setCountry(BindableUser::Country::Norway);
});
QSpinBox *ageSpinBox = w.findChild<QSpinBox *>("ageSpinBox");
@@ -105,7 +105,8 @@ int main(int argc, char *argv[])
// Track price changes
//! [update-ui]
auto priceChangeHandler = subscription.bindablePrice().subscribe([&] {
- priceDisplay->setText(QString::number(subscription.price()));
+ QLocale lc{QLocale::AnyLanguage, user.country()};
+ priceDisplay->setText(lc.toCurrencyString(subscription.price() / subscription.duration()));
});
auto priceValidHandler = subscription.bindableIsValid().subscribe([&] {
diff --git a/examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc b/examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc
index 8c36921ff8..40bfe9db2a 100644
--- a/examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc
+++ b/examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc
@@ -39,7 +39,7 @@
\image bindable_properties_example.png
- \section1 Modelling Subscription System with Signal/Slot Approach
+ \section1 Modeling Subscription System with Signal/Slot Approach
Let's first consider the usual pre-Qt 6 implementation.
To model the subscription service the \c Subscription class is used:
@@ -72,7 +72,7 @@
\note Both methods need to check if the data is actually changed and
only then emit the signals. \c setDuration() also needs to recalculate
- the price, when the duration has changed.
+ the price when the duration has changed.
The \c Subscription is not valid unless the user has a valid country and
age, so the validity is updated in the following way:
@@ -87,25 +87,25 @@
\snippet bindableproperties/subscription/user.cpp user-setters
In the \c main() function we initialize instances of \c User and
- \c Subsrcription:
+ \c Subscription:
\snippet bindableproperties/subscription/main.cpp init
- And do the proper signal-slot connections, to update the \c user and
- \c subsrcription data when UI elements change. That is straightforward,
+ And do the proper signal-slot connections to update the \c user and
+ \c subscription data when UI elements change. That is straightforward,
so we will skip this part.
- Next, we connect to \c Subscription::priceChanged(), to update the price
+ Next, we connect to \c Subscription::priceChanged() to update the price
in the UI when the price changes.
\snippet bindableproperties/subscription/main.cpp connect-price-changed
- We also connect to \c Subscription::isValidChanged(), to disable the price
+ We also connect to \c Subscription::isValidChanged() to disable the price
display if the subscription isn't valid.
\snippet bindableproperties/subscription/main.cpp connect-validity-changed
- Because the subsrcription price and validity also depend on the user's
+ Because the subscription price and validity also depend on the user's
country and age, we also need to connect to the \c User::countryChanged()
and \c User::ageChanged() signals and update \c subscription accordingly.
@@ -114,12 +114,12 @@
This works, but there are some problems:
\list
- \li There's a lot of boilerplate code for the signal-slot connections,
- to be able to react to changes to \c user or \c subscription. If any of
- the dependencies of the price changes, we need to remember to emit the
- corresponding notifier signals, to recalculate the price and update it in
+ \li There's a lot of boilerplate code for the signal-slot connections
+ in order to properly track changes to both \c user and \c subscription.
+ If any of the dependencies of the price changes, we need to remember to emit the
+ corresponding notifier signals, recalculate the price, and update it in
the UI.
- \li If more dependencies for price calculation are added in future, we'll
+ \li If more dependencies for price calculation are added in the future, we'll
need to add more signal-slot connections and make sure all the dependencies
are properly updated whenever any of them changes. The overall complexity
will grow, and the code will become harder to maintain.
@@ -133,7 +133,7 @@
Now let's see how the \l {Qt Bindable Properties} can help to solve the
same problem. First, let's have a look at the \c BindableSubscription class,
- which is similar to the \c Subscription class, but is implemented using the
+ which is similar to the \c Subscription class, but is implemented using
bindable properties:
\snippet bindableproperties/bindablesubscription/bindablesubscription.h bindable-subscription-class
@@ -180,7 +180,7 @@
changes the value. The subscriptions will stay alive as long as the
corresponding handlers are alive.
- Also note that the copy constructors of both \c BindableSubsrciption and
+ Also note that the copy constructors of both \c BindableSubscription and
\c BindableUser are disabled, since it's not defined what should happen
with their bindings when copying.
@@ -190,7 +190,7 @@
\list
\li The boilerplate code for the signal-slot connections is removed, the
dependencies are now tracked automatically.
- \li The code is easier to maintain. Adding more dependencies in future
+ \li The code is easier to maintain. Adding more dependencies in the future
will only require adding the corresponding bindable properties and setting
the binding expressions that reflect the relationships between each other.
\li The \c Subscription and \c User classes don't depend on the metaobject
diff --git a/examples/corelib/bindableproperties/subscription/main.cpp b/examples/corelib/bindableproperties/subscription/main.cpp
index 6ff0c960f1..3252d5ebad 100644
--- a/examples/corelib/bindableproperties/subscription/main.cpp
+++ b/examples/corelib/bindableproperties/subscription/main.cpp
@@ -87,15 +87,15 @@ int main(int argc, char *argv[])
// Initialize user data
QPushButton *germany = w.findChild<QPushButton *>("btnGermany");
QObject::connect(germany, &QPushButton::clicked, &user, [&] {
- user.setCountry(User::Germany);
+ user.setCountry(User::Country::Germany);
});
QPushButton *finland = w.findChild<QPushButton *>("btnFinland");
QObject::connect(finland, &QPushButton::clicked, &user, [&] {
- user.setCountry(User::Finland);
+ user.setCountry(User::Country::Finland);
});
QPushButton *norway = w.findChild<QPushButton *>("btnNorway");
QObject::connect(norway, &QPushButton::clicked, &user, [&] {
- user.setCountry(User::Norway);
+ user.setCountry(User::Country::Norway);
});
QSpinBox *ageSpinBox = w.findChild<QSpinBox *>("ageSpinBox");
@@ -112,7 +112,8 @@ int main(int argc, char *argv[])
//! [connect-price-changed]
QObject::connect(&subscription, &Subscription::priceChanged, [&] {
- priceDisplay->setText(QString::number(subscription.price()));
+ QLocale lc{QLocale::AnyLanguage, user.country()};
+ priceDisplay->setText(lc.toCurrencyString(subscription.price() / subscription.duration()));
});
//! [connect-price-changed]
diff --git a/examples/corelib/bindableproperties/subscription/subscription.cpp b/examples/corelib/bindableproperties/subscription/subscription.cpp
index 20efe825f3..109bd16959 100644
--- a/examples/corelib/bindableproperties/subscription/subscription.cpp
+++ b/examples/corelib/bindableproperties/subscription/subscription.cpp
@@ -104,10 +104,10 @@ double Subscription::calculateDiscount() const
int Subscription::basePrice() const
{
- if (m_user->country() == User::None)
+ if (m_user->country() == User::Country::AnyTerritory)
return 0;
- return (m_user->country() == User::Norway) ? 100 : 80;
+ return (m_user->country() == User::Country::Norway) ? 100 : 80;
}
//! [calculate-base-price]
@@ -117,7 +117,7 @@ int Subscription::basePrice() const
void Subscription::updateValidity()
{
bool isValid = m_isValid;
- m_isValid = m_user->country() != User::None && m_user->age() > 12;
+ m_isValid = m_user->country() != User::Country::AnyTerritory && m_user->age() > 12;
if (m_isValid != isValid)
emit isValidChanged();
diff --git a/examples/corelib/bindableproperties/subscription/subscription.h b/examples/corelib/bindableproperties/subscription/subscription.h
index 41d052e86f..d3121c0d26 100644
--- a/examples/corelib/bindableproperties/subscription/subscription.h
+++ b/examples/corelib/bindableproperties/subscription/subscription.h
@@ -62,7 +62,7 @@ class Subscription : public QObject
{
Q_OBJECT
public:
- enum Duration { Monthly = 1, Quarterly = 4, Yearly = 12 };
+ enum Duration { Monthly = 1, Quarterly = 3, Yearly = 12 };
Subscription(User *user);
diff --git a/examples/corelib/bindableproperties/subscription/user.h b/examples/corelib/bindableproperties/subscription/user.h
index 8c9ebb1009..223e660f62 100644
--- a/examples/corelib/bindableproperties/subscription/user.h
+++ b/examples/corelib/bindableproperties/subscription/user.h
@@ -51,6 +51,7 @@
#ifndef USER_H
#define USER_H
+#include <QLocale>
#include <QObject>
//! [user-class]
@@ -60,13 +61,9 @@ class User : public QObject
Q_OBJECT
public:
- enum Country {
- None,
- Finland,
- Germany,
- Norway,
- };
+ using Country = QLocale::Territory;
+public:
Country country() const { return m_country; }
void setCountry(Country country);
@@ -78,8 +75,8 @@ signals:
void ageChanged();
private:
- Country m_country = Country::None;
- int m_age = 0;
+ Country m_country { QLocale::AnyTerritory };
+ int m_age { 0 };
};
//! [user-class]
diff --git a/examples/corelib/serialization/savegame/character.cpp b/examples/corelib/serialization/savegame/character.cpp
index 046cde3091..266fe3b921 100644
--- a/examples/corelib/serialization/savegame/character.cpp
+++ b/examples/corelib/serialization/savegame/character.cpp
@@ -53,10 +53,8 @@
#include <QMetaEnum>
#include <QTextStream>
-Character::Character() :
- mLevel(0),
- mClassType(Warrior) {
-}
+Character::Character()
+ = default;
Character::Character(const QString &name,
int level,
diff --git a/examples/corelib/serialization/savegame/character.h b/examples/corelib/serialization/savegame/character.h
index cbf06d7fd6..2cabcd17b4 100644
--- a/examples/corelib/serialization/savegame/character.h
+++ b/examples/corelib/serialization/savegame/character.h
@@ -58,7 +58,7 @@
//! [0]
class Character
{
- Q_GADGET;
+ Q_GADGET
public:
enum ClassType {
@@ -84,8 +84,8 @@ public:
void print(int indentation = 0) const;
private:
QString mName;
- int mLevel;
- ClassType mClassType;
+ int mLevel = 0;
+ ClassType mClassType = Warrior;
};
//! [0]
diff --git a/examples/corelib/serialization/savegame/game.cpp b/examples/corelib/serialization/savegame/game.cpp
index bb7c2013f2..02c0851869 100644
--- a/examples/corelib/serialization/savegame/game.cpp
+++ b/examples/corelib/serialization/savegame/game.cpp
@@ -168,8 +168,8 @@ void Game::read(const QJsonObject &json)
QJsonArray levelArray = json["levels"].toArray();
mLevels.clear();
mLevels.reserve(levelArray.size());
- for (int levelIndex = 0; levelIndex < levelArray.size(); ++levelIndex) {
- QJsonObject levelObject = levelArray[levelIndex].toObject();
+ for (const QJsonValue &v : levelArray) {
+ QJsonObject levelObject = v.toObject();
Level level;
level.read(levelObject);
mLevels.append(level);
diff --git a/examples/corelib/serialization/savegame/game.h b/examples/corelib/serialization/savegame/game.h
index dfcb27eb1c..2934d5184e 100644
--- a/examples/corelib/serialization/savegame/game.h
+++ b/examples/corelib/serialization/savegame/game.h
@@ -51,12 +51,12 @@
#ifndef GAME_H
#define GAME_H
-#include <QJsonObject>
-#include <QList>
-
#include "character.h"
#include "level.h"
+#include <QJsonObject>
+#include <QList>
+
//! [0]
class Game
{
diff --git a/examples/corelib/serialization/savegame/level.cpp b/examples/corelib/serialization/savegame/level.cpp
index ea6ef147b9..6351fbf733 100644
--- a/examples/corelib/serialization/savegame/level.cpp
+++ b/examples/corelib/serialization/savegame/level.cpp
@@ -82,8 +82,8 @@ void Level::read(const QJsonObject &json)
QJsonArray npcArray = json["npcs"].toArray();
mNpcs.clear();
mNpcs.reserve(npcArray.size());
- for (int npcIndex = 0; npcIndex < npcArray.size(); ++npcIndex) {
- QJsonObject npcObject = npcArray[npcIndex].toObject();
+ for (const QJsonValue &v : npcArray) {
+ QJsonObject npcObject = v.toObject();
Character npc;
npc.read(npcObject);
mNpcs.append(npc);
diff --git a/examples/corelib/serialization/savegame/level.h b/examples/corelib/serialization/savegame/level.h
index ecffde8f22..ec1873ed33 100644
--- a/examples/corelib/serialization/savegame/level.h
+++ b/examples/corelib/serialization/savegame/level.h
@@ -51,17 +51,17 @@
#ifndef LEVEL_H
#define LEVEL_H
+#include "character.h"
+
#include <QJsonObject>
#include <QList>
-#include "character.h"
-
//! [0]
class Level
{
public:
Level() = default;
- Level(const QString &name);
+ explicit Level(const QString &name);
QString name() const;
diff --git a/examples/corelib/serialization/savegame/main.cpp b/examples/corelib/serialization/savegame/main.cpp
index d091684211..6115627574 100644
--- a/examples/corelib/serialization/savegame/main.cpp
+++ b/examples/corelib/serialization/savegame/main.cpp
@@ -48,10 +48,11 @@
**
****************************************************************************/
+#include "game.h"
+
#include <QCoreApplication>
#include <QTextStream>
-#include "game.h"
//! [0]
int main(int argc, char *argv[])
{
diff --git a/examples/corelib/threads/doc/src/mandelbrot.qdoc b/examples/corelib/threads/doc/src/mandelbrot.qdoc
index 2b12743538..ff05249e64 100644
--- a/examples/corelib/threads/doc/src/mandelbrot.qdoc
+++ b/examples/corelib/threads/doc/src/mandelbrot.qdoc
@@ -37,11 +37,11 @@
\image mandelbrot-example.png Screenshot of the Mandelbrot example
- The heavy computation here is the Mandelbrot set, probably the
- world's most famous fractal. These days, while sophisticated
- programs such as \l{http://matek.hu/xaos/doku.php}{XaoS} that provide real-time zooming in the
- Mandelbrot set, the standard Mandelbrot algorithm is just slow
- enough for our purposes.
+ The heavy computation here is the Mandelbrot set, probably the world's most
+ famous fractal. These days, while sophisticated programs, such as
+ \l{https://xaos-project.github.io/}{XaoS}, provide real-time zooming in
+ the Mandelbrot set, the standard Mandelbrot algorithm is just slow enough
+ for our purposes.
In real life, the approach described here is applicable to a
large set of problems, including synchronous network I/O and
diff --git a/examples/dbus/chat/chat.pro b/examples/dbus/chat/chat.pro
index 631a876954..93d3178177 100644
--- a/examples/dbus/chat/chat.pro
+++ b/examples/dbus/chat/chat.pro
@@ -7,6 +7,8 @@ FORMS += chatmainwindow.ui chatsetnickname.ui
DBUS_ADAPTORS += org.example.chat.xml
DBUS_INTERFACES += org.example.chat.xml
+CONFIG += no_batch # work around QTBUG-96513
+
# install
target.path = $$[QT_INSTALL_EXAMPLES]/dbus/chat
INSTALLS += target
diff --git a/examples/dbus/remotecontrolledcar/car/car.pro b/examples/dbus/remotecontrolledcar/car/car.pro
index 35a186c7fe..5e354e3d0b 100644
--- a/examples/dbus/remotecontrolledcar/car/car.pro
+++ b/examples/dbus/remotecontrolledcar/car/car.pro
@@ -4,6 +4,8 @@ DBUS_ADAPTORS += car.xml
HEADERS += car.h
SOURCES += car.cpp main.cpp
+CONFIG += no_batch # work around QTBUG-96513
+
# install
target.path = $$[QT_INSTALL_EXAMPLES]/dbus/remotecontrolledcar/car
INSTALLS += target
diff --git a/examples/network/doc/src/blockingfortuneclient.qdoc b/examples/network/doc/src/blockingfortuneclient.qdoc
index d1c0aa79bf..5aa80fa47c 100644
--- a/examples/network/doc/src/blockingfortuneclient.qdoc
+++ b/examples/network/doc/src/blockingfortuneclient.qdoc
@@ -147,7 +147,7 @@
The final part of our loop is that we acquire the mutex so that we can
safely read from our member data. We then let the thread go to sleep by
calling QWaitCondition::wait(). At this point, we can go back to
- requestNewFortune() and look closed at the call to wakeOne():
+ requestNewFortune() and look closely at the call to wakeOne():
\snippet blockingfortuneclient/fortunethread.cpp 1
\dots
diff --git a/examples/network/doc/src/fortuneserver.qdoc b/examples/network/doc/src/fortuneserver.qdoc
index acd05da696..96dcf8e00a 100644
--- a/examples/network/doc/src/fortuneserver.qdoc
+++ b/examples/network/doc/src/fortuneserver.qdoc
@@ -72,7 +72,7 @@
to the connecting socket. This is a common way to transfer binary data
using QTcpSocket. First we create a QByteArray and a QDataStream object,
passing the bytearray to QDataStream's constructor. We then explicitly set
- the protocol version of QDataStream to QDataStream::Qt_4_0 to ensure that
+ the protocol version of QDataStream to QDataStream::Qt_5_10 to ensure that
we can communicate with clients from future versions of Qt (see
QDataStream::setVersion()). We continue by streaming in a random fortune.
diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h
index d4dcbcf3db..3934cbf074 100644
--- a/examples/opengl/hellowindow/hellowindow.h
+++ b/examples/opengl/hellowindow/hellowindow.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef HELLOWINDOW_H
+#define HELLOWINDOW_H
+
#include <QWindow>
#include <QColor>
@@ -117,3 +120,5 @@ private:
QColor m_color;
const QSharedPointer<Renderer> m_renderer;
};
+
+#endif // HELLOWINDOW_H
diff --git a/examples/opengl/openglwindow/openglwindow.h b/examples/opengl/openglwindow/openglwindow.h
index 8db943ddde..f824c22c9f 100644
--- a/examples/opengl/openglwindow/openglwindow.h
+++ b/examples/opengl/openglwindow/openglwindow.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef OPENGLWINDOW_H
+#define OPENGLWINDOW_H
+
#include <QWindow>
#include <QOpenGLFunctions>
@@ -89,3 +92,4 @@ private:
};
//! [1]
+#endif // OPENGLWINDOW_H
diff --git a/examples/opengl/paintedwindow/paintedwindow.h b/examples/opengl/paintedwindow/paintedwindow.h
index 972d8d10bd..14964e35ff 100644
--- a/examples/opengl/paintedwindow/paintedwindow.h
+++ b/examples/opengl/paintedwindow/paintedwindow.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef PAINTEDWINDOW_H
+#define PAINTEDWINDOW_H
+
#include <QWindow>
#include <QtGui/qopengl.h>
@@ -102,3 +105,5 @@ private:
QPropertyAnimation *m_animation;
QTimer *m_paintTimer;
};
+
+#endif // PAINTEDWINDOW_H
diff --git a/examples/qpa/windows/window.h b/examples/qpa/windows/window.h
index 438be413b8..1387f4e3bf 100644
--- a/examples/qpa/windows/window.h
+++ b/examples/qpa/windows/window.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef WINDOW_H
+#define WINDOW_H
+
#include <QWindow>
#include <QImage>
@@ -81,3 +84,5 @@ private:
QBackingStore *m_backingStore;
int m_renderTimer;
};
+
+#endif // WINDOW_H
diff --git a/examples/vulkan/hellovulkantexture/hellovulkantexture.h b/examples/vulkan/hellovulkantexture/hellovulkantexture.h
index a8c96d1987..39cc0387c6 100644
--- a/examples/vulkan/hellovulkantexture/hellovulkantexture.h
+++ b/examples/vulkan/hellovulkantexture/hellovulkantexture.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef HELLOVULKANTEXTURE_H
+#define HELLOVULKANTEXTURE_H
+
#include <QVulkanWindow>
#include <QImage>
@@ -106,3 +109,5 @@ class VulkanWindow : public QVulkanWindow
public:
QVulkanWindowRenderer *createRenderer() override;
};
+
+#endif // HELLOVULKANTEXTURE_H
diff --git a/examples/vulkan/hellovulkanwidget/hellovulkanwidget.h b/examples/vulkan/hellovulkanwidget/hellovulkanwidget.h
index e70d331ae8..e428c6ae93 100644
--- a/examples/vulkan/hellovulkanwidget/hellovulkanwidget.h
+++ b/examples/vulkan/hellovulkanwidget/hellovulkanwidget.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef HELLOVULKANWIDGET_H
+#define HELLOVULKANWIDGET_H
+
#include "../shared/trianglerenderer.h"
#include <QWidget>
@@ -98,3 +101,5 @@ signals:
void vulkanInfoReceived(const QString &text);
void frameQueued(int colorValue);
};
+
+#endif // HELLOVULKANWIDGET_H
diff --git a/examples/vulkan/hellovulkanwindow/hellovulkanwindow.h b/examples/vulkan/hellovulkanwindow/hellovulkanwindow.h
index 5f52e402ca..7a6db84ae3 100644
--- a/examples/vulkan/hellovulkanwindow/hellovulkanwindow.h
+++ b/examples/vulkan/hellovulkanwindow/hellovulkanwindow.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef HELLOVULKANWINDOW_H
+#define HELLOVULKANWINDOW_H
+
#include <QVulkanWindow>
//! [0]
@@ -75,3 +78,5 @@ public:
QVulkanWindowRenderer *createRenderer() override;
};
//! [0]
+
+#endif // HELLOVULKANWINDOW_H
diff --git a/examples/vulkan/shared/trianglerenderer.h b/examples/vulkan/shared/trianglerenderer.h
index 9a33291a95..bd3daf1d64 100644
--- a/examples/vulkan/shared/trianglerenderer.h
+++ b/examples/vulkan/shared/trianglerenderer.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef TRIANGLERENDERER_H
+#define TRIANGLERENDERER_H
+
#include <QVulkanWindow>
class TriangleRenderer : public QVulkanWindowRenderer
@@ -83,3 +86,5 @@ protected:
QMatrix4x4 m_proj;
float m_rotation = 0.0f;
};
+
+#endif // TRIANGLERENDERER_H
diff --git a/examples/widgets/animation/easing/animation.h b/examples/widgets/animation/easing/animation.h
index 696257bb4a..d78997d5ff 100644
--- a/examples/widgets/animation/easing/animation.h
+++ b/examples/widgets/animation/easing/animation.h
@@ -62,8 +62,8 @@ public:
CirclePath,
NPathTypes
};
- Animation(QObject *target, const QByteArray &prop)
- : QPropertyAnimation(target, prop)
+ Animation(QObject *target, const QByteArray &prop, QObject *parent = nullptr)
+ : QPropertyAnimation(target, prop, parent)
{
setPathType(LinearPath);
}
diff --git a/examples/widgets/animation/easing/window.cpp b/examples/widgets/animation/easing/window.cpp
index 7b4fe1d912..d0deb843e4 100644
--- a/examples/widgets/animation/easing/window.cpp
+++ b/examples/widgets/animation/easing/window.cpp
@@ -82,7 +82,7 @@ Window::Window(QWidget *parent)
m_scene.addItem(m_item);
m_ui.graphicsView->setScene(&m_scene);
- m_anim = new Animation(m_item, "pos");
+ m_anim = new Animation(m_item, "pos", this);
m_anim->setEasingCurve(QEasingCurve::OutBounce);
m_ui.easingCurvePicker->setCurrentRow(int(QEasingCurve::OutBounce));
diff --git a/examples/widgets/animation/easing/window.h b/examples/widgets/animation/easing/window.h
index 0c49dd6e8a..51c7792e19 100644
--- a/examples/widgets/animation/easing/window.h
+++ b/examples/widgets/animation/easing/window.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef WINDOW_H
+#define WINDOW_H
+
#include <QtWidgets>
#include "ui_form.h"
@@ -84,3 +87,5 @@ private:
Animation *m_anim;
QSize m_iconSize;
};
+
+#endif // WINDOW_H
diff --git a/examples/widgets/doc/src/tooltips.qdoc b/examples/widgets/doc/src/tooltips.qdoc
index a278215503..da3f1bd489 100644
--- a/examples/widgets/doc/src/tooltips.qdoc
+++ b/examples/widgets/doc/src/tooltips.qdoc
@@ -148,6 +148,10 @@
private \c createShapeItem(), \c initialItemPosition() and \c
initialItemColor() functions.
+ \snippet widgets/tooltips/sortingbox.cpp 27
+
+ In the destructor, we delete all shape items.
+
\snippet widgets/tooltips/sortingbox.cpp 5
QWidget::event() is the main event handler and receives all the
@@ -223,8 +227,9 @@
If an item covers the position, we store a pointer to that item
and the event's position. If several of the shape items cover the
position, we store the pointer to the uppermost item. Finally, we
- move the shape item to the end of the list, and make a call to the
- QWidget::update() function to make the item appear on top.
+ move the shape item's pointer to the end of the list, and make
+ a call to the QWidget::update() function to make the item appear
+ on top.
The QWidget::update() function does not cause an immediate
repaint; instead it schedules a paint event for processing when Qt
@@ -314,10 +319,9 @@
The \c createShapeItem() function creates a single shape item. It
sets the path, tooltip, position and color, using the item's own
- functions. In the end, the function appends the new item to the
- list of shape items, and calls the QWidget::update() function to
- make it appear with the other items within the \c SortingBox
- widget.
+ functions. In the end, the function appends the new item's pointer
+ to the list of shape items, and calls QWidget::update() to make
+ it appear with the other items within the \c SortingBox widget.
\snippet widgets/tooltips/sortingbox.cpp 22
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.h b/examples/widgets/graphicsview/flowlayout/flowlayout.h
index 14251072ec..d8ec253792 100644
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.h
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef FLOWLAYOUT_H
+#define FLOWLAYOUT_H
+
#include <QGraphicsLayout>
class FlowLayout : public QGraphicsLayout
@@ -84,3 +87,5 @@ inline void FlowLayout::addItem(QGraphicsLayoutItem *item)
{
insertItem(-1, item);
}
+
+#endif // FLOWLAYOUT_H
diff --git a/examples/widgets/graphicsview/flowlayout/window.h b/examples/widgets/graphicsview/flowlayout/window.h
index 24a7cf908b..9323125fd4 100644
--- a/examples/widgets/graphicsview/flowlayout/window.h
+++ b/examples/widgets/graphicsview/flowlayout/window.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef WINDOW_H
+#define WINDOW_H
+
#include <QGraphicsWidget>
class Window : public QGraphicsWidget
@@ -56,3 +59,5 @@ class Window : public QGraphicsWidget
public:
Window(QGraphicsItem *parent = nullptr);
};
+
+#endif // WINDOW_H
diff --git a/examples/widgets/layouts/basiclayouts/dialog.cpp b/examples/widgets/layouts/basiclayouts/dialog.cpp
index 8376820545..d6d228920f 100644
--- a/examples/widgets/layouts/basiclayouts/dialog.cpp
+++ b/examples/widgets/layouts/basiclayouts/dialog.cpp
@@ -83,9 +83,24 @@ Dialog::Dialog()
mainLayout->addWidget(formGroupBox);
mainLayout->addWidget(bigEditor);
mainLayout->addWidget(buttonBox);
-//! [4] //! [5]
- setLayout(mainLayout);
+//! [4]
+ QWidget *scrollAreaContent = new QWidget;
+ scrollAreaContent->setLayout(mainLayout);
+ QScrollArea *scrollArea = new QScrollArea;
+ scrollArea->setFrameShape(QFrame::NoFrame);
+ scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ scrollArea->setWidgetResizable(true);
+ scrollArea->verticalScrollBar()->setStyleSheet("QScrollBar:vertical {width: 20px;}");
+
+ scrollArea->setWidget(scrollAreaContent);
+
+ QVBoxLayout *scrollLayout = new QVBoxLayout;
+ scrollLayout->setContentsMargins(0,0,0,0);
+ scrollLayout->addWidget(scrollArea);
+
+//! [5]
+ setLayout(scrollLayout);
setWindowTitle(tr("Basic Layouts"));
}
//! [5]
diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp
index a220fb42fa..cc055e63bc 100644
--- a/examples/widgets/painting/composition/composition.cpp
+++ b/examples/widgets/painting/composition/composition.cpp
@@ -266,6 +266,7 @@ CompositionRenderer::CompositionRenderer(QWidget *parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
#if QT_CONFIG(opengl)
m_pbuffer_size = 1024;
+ m_base_tex = 0;
#endif
}
@@ -361,6 +362,7 @@ void CompositionRenderer::paint(QPainter *painter)
{
#if QT_CONFIG(opengl)
if (usesOpenGL() && glWindow()->isValid()) {
+ auto *funcs = QOpenGLContext::currentContext()->functions();
if (!m_blitter.isCreated())
m_blitter.create();
@@ -385,10 +387,13 @@ void CompositionRenderer::paint(QPainter *painter)
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
drawBase(p);
p.end();
+ if (m_base_tex)
+ funcs->glDeleteTextures(1, &m_base_tex);
m_base_tex = m_fbo->takeTexture();
}
painter->beginNativePainting();
+ uint compositingTex;
{
QPainter p(m_fbo.get());
p.beginNativePainting();
@@ -400,19 +405,18 @@ void CompositionRenderer::paint(QPainter *painter)
p.endNativePainting();
drawSource(p);
p.end();
- m_compositing_tex = m_fbo->takeTexture();
+ compositingTex = m_fbo->texture();
}
painter->endNativePainting();
painter->beginNativePainting();
- auto *funcs = QOpenGLContext::currentContext()->functions();
funcs->glEnable(GL_BLEND);
funcs->glBlendEquation(GL_FUNC_ADD);
funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
m_blitter.bind();
const QRect targetRect(QPoint(0, 0), m_fbo->size());
const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), size()));
- m_blitter.blit(m_compositing_tex, target, QOpenGLTextureBlitter::OriginBottomLeft);
+ m_blitter.blit(compositingTex, target, QOpenGLTextureBlitter::OriginBottomLeft);
m_blitter.release();
painter->endNativePainting();
} else
diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h
index 52ca7919b0..88bc50dc80 100644
--- a/examples/widgets/painting/composition/composition.h
+++ b/examples/widgets/painting/composition/composition.h
@@ -195,7 +195,6 @@ private:
std::unique_ptr<QFboPaintDevice> m_fbo;
int m_pbuffer_size; // width==height==size of pbuffer
uint m_base_tex;
- uint m_compositing_tex;
QSize m_previous_size;
QOpenGLTextureBlitter m_blitter;
#endif
diff --git a/examples/widgets/painting/shared/fbopaintdevice.cpp b/examples/widgets/painting/shared/fbopaintdevice.cpp
index 9368293218..b7e7073501 100644
--- a/examples/widgets/painting/shared/fbopaintdevice.cpp
+++ b/examples/widgets/painting/shared/fbopaintdevice.cpp
@@ -71,11 +71,13 @@ QFboPaintDevice::QFboPaintDevice(const QSize &size, bool flipped, bool clearOnIn
context()->functions()->glClearColor(0, 0, 0, 0);
context()->functions()->glClear(GL_COLOR_BUFFER_BIT);
}
+ m_resolvedFbo = new QOpenGLFramebufferObject(m_framebufferObject->size(), m_framebufferObject->attachment());
}
QFboPaintDevice::~QFboPaintDevice()
{
delete m_framebufferObject;
+ delete m_resolvedFbo;
delete m_surface;
}
@@ -87,12 +89,19 @@ void QFboPaintDevice::ensureActiveTarget()
m_framebufferObject->bind();
}
+GLuint QFboPaintDevice::texture()
+{
+ m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
+ QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
+ return m_resolvedFbo->texture();
+}
+
GLuint QFboPaintDevice::takeTexture()
{
- // We have multisamples so we can't just forward takeTexture().
- QOpenGLFramebufferObject resolvedFbo(m_framebufferObject->size(), m_framebufferObject->attachment());
- QOpenGLFramebufferObject::blitFramebuffer(&resolvedFbo, m_framebufferObject);
- return resolvedFbo.takeTexture();
+ m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
+ // We have multisamples so we can't just forward takeTexture(), have to resolve first.
+ QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
+ return m_resolvedFbo->takeTexture();
}
QImage QFboPaintDevice::toImage() const
diff --git a/examples/widgets/painting/shared/fbopaintdevice.h b/examples/widgets/painting/shared/fbopaintdevice.h
index a42bcc756d..e2dd31427b 100644
--- a/examples/widgets/painting/shared/fbopaintdevice.h
+++ b/examples/widgets/painting/shared/fbopaintdevice.h
@@ -69,6 +69,7 @@ public:
bool isValid() const { return m_framebufferObject->isValid(); }
GLuint handle() const { return m_framebufferObject->handle(); }
+ GLuint texture();
GLuint takeTexture();
QImage toImage() const;
@@ -83,6 +84,7 @@ public:
private:
QOpenGLFramebufferObject *m_framebufferObject;
+ QOpenGLFramebufferObject *m_resolvedFbo;
QSurface *m_surface;
};
diff --git a/examples/widgets/tools/echoplugin/CMakeLists.txt b/examples/widgets/tools/echoplugin/CMakeLists.txt
index 6e32a4de09..69bb6e981a 100644
--- a/examples/widgets/tools/echoplugin/CMakeLists.txt
+++ b/examples/widgets/tools/echoplugin/CMakeLists.txt
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.16)
project(plugandpaint LANGUAGES CXX)
-find_package(Qt6 COMPONENTS Core Gui Widgets)
-
set(CMAKE_AUTOMOC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
@@ -11,5 +9,7 @@ endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/echoplugin")
+find_package(Qt6 COMPONENTS Core Gui Widgets)
+
add_subdirectory(plugin)
add_subdirectory(echowindow)
diff --git a/examples/widgets/tools/plugandpaint/CMakeLists.txt b/examples/widgets/tools/plugandpaint/CMakeLists.txt
index e681812dad..cc1dae43ff 100644
--- a/examples/widgets/tools/plugandpaint/CMakeLists.txt
+++ b/examples/widgets/tools/plugandpaint/CMakeLists.txt
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.16)
project(plugandpaint LANGUAGES CXX)
-find_package(Qt6 COMPONENTS Core Gui Widgets)
-
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
@@ -13,5 +11,7 @@ endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/plugandpaint")
+find_package(Qt6 COMPONENTS Core Gui Widgets)
+
add_subdirectory(plugins)
add_subdirectory(app)
diff --git a/examples/widgets/tools/styleplugin/CMakeLists.txt b/examples/widgets/tools/styleplugin/CMakeLists.txt
index 33412f5306..31c49cc754 100644
--- a/examples/widgets/tools/styleplugin/CMakeLists.txt
+++ b/examples/widgets/tools/styleplugin/CMakeLists.txt
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.16)
project(styleplugin LANGUAGES CXX)
-find_package(Qt6 COMPONENTS Widgets)
-
set(CMAKE_AUTOMOC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
@@ -11,5 +9,7 @@ endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/styleplugin")
+find_package(Qt6 COMPONENTS Widgets)
+
add_subdirectory(stylewindow)
add_subdirectory(plugin)
diff --git a/examples/widgets/widgets/groupbox/window.cpp b/examples/widgets/widgets/groupbox/window.cpp
index 95c4f216fe..6a939d4f7d 100644
--- a/examples/widgets/widgets/groupbox/window.cpp
+++ b/examples/widgets/widgets/groupbox/window.cpp
@@ -183,12 +183,10 @@ QGroupBox *Window::createPushButtonGroup()
popupButton->setMenu(menu);
//! [12]
- QAction *newAction = menu->addAction(tr("Submenu"));
- QMenu *subMenu = new QMenu(tr("Popup Submenu"));
+ QMenu *subMenu = menu->addMenu(tr("Submenu"));
subMenu->addAction(tr("Item 1"));
subMenu->addAction(tr("Item 2"));
subMenu->addAction(tr("Item 3"));
- newAction->setMenu(subMenu);
//! [13]
QVBoxLayout *vbox = new QVBoxLayout;
diff --git a/examples/widgets/widgets/sliders/window.cpp b/examples/widgets/widgets/sliders/window.cpp
index 916f206379..fc6ac6f193 100644
--- a/examples/widgets/widgets/sliders/window.cpp
+++ b/examples/widgets/widgets/sliders/window.cpp
@@ -50,10 +50,8 @@
#include "slidersgroup.h"
#include "window.h"
-
#include <QCheckBox>
#include <QComboBox>
-#include <QHBoxLayout>
#include <QLabel>
#include <QSpinBox>
#include <QStackedWidget>
@@ -81,9 +79,10 @@ Window::Window(QWidget *parent)
connect(valueSpinBox, &QSpinBox::valueChanged,
horizontalSliders, &SlidersGroup::setValue);
- QHBoxLayout *layout = new QHBoxLayout;
- layout->addWidget(controlsGroup);
- layout->addWidget(stackedWidget);
+ layout = new QGridLayout;
+ layout->addWidget(stackedWidget, 0, 1);
+ layout->addWidget(controlsGroup, 0, 0);
+
setLayout(layout);
minimumSpinBox->setValue(0);
@@ -157,5 +156,37 @@ void Window::createControls(const QString &title)
controlsLayout->addWidget(invertedKeyBindings, 1, 2);
controlsLayout->addWidget(orientationCombo, 3, 0, 1, 3);
controlsGroup->setLayout(controlsLayout);
+
}
//! [8]
+
+
+void Window::resizeEvent(QResizeEvent *e)
+{
+ if (width() == 0 || height() == 0)
+ return;
+
+ const double aspectRatio = double(width()) / double(height());
+
+ if ((aspectRatio < 1.0) && (oldAspectRatio > 1.0)) {
+ layout->removeWidget(controlsGroup);
+ layout->removeWidget(stackedWidget);
+
+ layout->addWidget(stackedWidget, 1, 0);
+ layout->addWidget(controlsGroup, 0, 0);
+
+ oldAspectRatio = aspectRatio;
+ }
+ else if ((aspectRatio > 1.0) && (oldAspectRatio < 1.0)) {
+ layout->removeWidget(controlsGroup);
+ layout->removeWidget(stackedWidget);
+
+ layout->addWidget(stackedWidget, 0, 1);
+ layout->addWidget(controlsGroup, 0, 0);
+
+ oldAspectRatio = aspectRatio;
+ }
+}
+
+
+
diff --git a/examples/widgets/widgets/sliders/window.h b/examples/widgets/widgets/sliders/window.h
index 4894781ac2..7c2297bd83 100644
--- a/examples/widgets/widgets/sliders/window.h
+++ b/examples/widgets/widgets/sliders/window.h
@@ -52,6 +52,7 @@
#define WINDOW_H
#include <QWidget>
+#include <QGridLayout>
QT_BEGIN_NAMESPACE
class QCheckBox;
@@ -73,6 +74,7 @@ public:
private:
void createControls(const QString &title);
+ void resizeEvent(QResizeEvent *e);
SlidersGroup *horizontalSliders;
SlidersGroup *verticalSliders;
@@ -88,6 +90,8 @@ private:
QSpinBox *maximumSpinBox;
QSpinBox *valueSpinBox;
QComboBox *orientationCombo;
+ QGridLayout *layout;
+ double oldAspectRatio;
};
//! [0]
diff --git a/examples/widgets/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp
index d993b098b2..733e567873 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.cpp
+++ b/examples/widgets/widgets/tooltips/sortingbox.cpp
@@ -106,6 +106,13 @@ SortingBox::SortingBox(QWidget *parent)
}
//! [4]
+//! [27]
+SortingBox::~SortingBox()
+{
+ qDeleteAll(shapeItems);
+}
+//! [27]
+
//! [5]
bool SortingBox::event(QEvent *event)
{
@@ -114,7 +121,7 @@ bool SortingBox::event(QEvent *event)
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
int index = itemAt(helpEvent->pos());
if (index != -1) {
- QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip());
+ QToolTip::showText(helpEvent->globalPos(), shapeItems[index]->toolTip());
} else {
QToolTip::hideText();
event->ignore();
@@ -144,13 +151,13 @@ void SortingBox::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
- for (const ShapeItem &shapeItem : qAsConst(shapeItems)) {
+ for (const ShapeItem *shapeItem : std::as_const(shapeItems)) {
//! [8] //! [9]
- painter.translate(shapeItem.position());
+ painter.translate(shapeItem->position());
//! [9] //! [10]
- painter.setBrush(shapeItem.color());
- painter.drawPath(shapeItem.path());
- painter.translate(-shapeItem.position());
+ painter.setBrush(shapeItem->color());
+ painter.drawPath(shapeItem->path());
+ painter.translate(-shapeItem->position());
}
}
//! [10]
@@ -161,7 +168,7 @@ void SortingBox::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton) {
int index = itemAt(event->position().toPoint());
if (index != -1) {
- itemInMotion = &shapeItems[index];
+ itemInMotion = shapeItems[index];
previousPosition = event->position().toPoint();
shapeItems.move(index, shapeItems.size() - 1);
update();
@@ -216,11 +223,11 @@ void SortingBox::createNewTriangle()
//! [16]
//! [17]
-int SortingBox::itemAt(const QPoint &pos)
+qsizetype SortingBox::itemAt(const QPoint &pos)
{
- for (int i = shapeItems.size() - 1; i >= 0; --i) {
- const ShapeItem &item = shapeItems[i];
- if (item.path().contains(pos - item.position()))
+ for (qsizetype i = shapeItems.size() - 1; i >= 0; --i) {
+ const ShapeItem *item = shapeItems[i];
+ if (item->path().contains(pos - item->position()))
return i;
}
return -1;
@@ -255,11 +262,11 @@ void SortingBox::createShapeItem(const QPainterPath &path,
const QString &toolTip, const QPoint &pos,
const QColor &color)
{
- ShapeItem shapeItem;
- shapeItem.setPath(path);
- shapeItem.setToolTip(toolTip);
- shapeItem.setPosition(pos);
- shapeItem.setColor(color);
+ ShapeItem *shapeItem = new ShapeItem;
+ shapeItem->setPath(path);
+ shapeItem->setToolTip(toolTip);
+ shapeItem->setPosition(pos);
+ shapeItem->setColor(color);
shapeItems.append(shapeItem);
update();
}
diff --git a/examples/widgets/widgets/tooltips/sortingbox.h b/examples/widgets/widgets/tooltips/sortingbox.h
index 3d0cecea2b..90534ab13d 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.h
+++ b/examples/widgets/widgets/tooltips/sortingbox.h
@@ -68,6 +68,7 @@ class SortingBox : public QWidget
public:
SortingBox(QWidget *parent = nullptr);
+ ~SortingBox();
protected:
bool event(QEvent *event) override;
@@ -88,7 +89,7 @@ private:
int updateButtonGeometry(QToolButton *button, int x, int y);
void createShapeItem(const QPainterPath &path, const QString &toolTip,
const QPoint &pos, const QColor &color);
- int itemAt(const QPoint &pos);
+ qsizetype itemAt(const QPoint &pos);
void moveItemTo(const QPoint &pos);
QPoint initialItemPosition(const QPainterPath &path);
QPoint randomItemPosition();
@@ -99,7 +100,7 @@ private:
const char *member);
//! [2]
- QList<ShapeItem> shapeItems;
+ QList<ShapeItem *> shapeItems;
QPainterPath circlePath;
QPainterPath squarePath;
QPainterPath trianglePath;
diff --git a/examples/widgets/widgets/validators/validatorwidget.h b/examples/widgets/widgets/validators/validatorwidget.h
index bcc4a9b91e..7b80c58504 100644
--- a/examples/widgets/widgets/validators/validatorwidget.h
+++ b/examples/widgets/widgets/validators/validatorwidget.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef VALIDATORWIDGET_H
+#define VALIDATORWIDGET_H
+
#include <QWidget>
#include "ui_validators.h"
@@ -62,3 +65,5 @@ private slots:
void updateValidator();
void updateDoubleValidator();
};
+
+#endif // VALIDATORWIDGET_H
diff --git a/examples/widgets/widgets/windowflags/previewwindow.cpp b/examples/widgets/widgets/windowflags/previewwindow.cpp
index d7ebed7b3c..c05e486c1d 100644
--- a/examples/widgets/widgets/windowflags/previewwindow.cpp
+++ b/examples/widgets/widgets/windowflags/previewwindow.cpp
@@ -124,6 +124,8 @@ void PreviewWindow::setWindowFlags(Qt::WindowFlags flags)
text += "\n| Qt::WindowShadeButtonHint";
if (flags & Qt::WindowStaysOnTopHint)
text += "\n| Qt::WindowStaysOnTopHint";
+ if (flags & Qt::WindowStaysOnBottomHint)
+ text += "\n| Qt::WindowStaysOnBottomHint";
if (flags & Qt::CustomizeWindowHint)
text += "\n| Qt::CustomizeWindowHint";