summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/animation/easing/window.cpp7
-rw-r--r--examples/widgets/animation/easing/window.h2
-rw-r--r--examples/widgets/desktop/screenshot/screenshot.cpp2
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.cpp5
-rw-r--r--examples/widgets/doc/dropsite.qdoc12
-rw-r--r--examples/widgets/doc/src/gallery.qdoc36
-rw-r--r--examples/widgets/doc/src/icons.qdoc38
-rw-r--r--examples/widgets/doc/src/imageviewer.qdoc4
-rw-r--r--examples/widgets/doc/src/styles.qdoc1
-rw-r--r--examples/widgets/draganddrop/draggableicons/dragwidget.cpp2
-rw-r--r--examples/widgets/draganddrop/draggabletext/dragwidget.cpp2
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.cpp21
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.h2
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp6
-rw-r--r--examples/widgets/gallery/gallery.pro10
-rw-r--r--examples/widgets/gallery/main.cpp75
-rw-r--r--examples/widgets/gallery/widgetgallery.cpp474
-rw-r--r--examples/widgets/gallery/widgetgallery.h90
-rw-r--r--examples/widgets/graphicsview/boxes/scene.h1
-rw-r--r--examples/widgets/graphicsview/chip/view.cpp4
-rw-r--r--examples/widgets/graphicsview/collidingmice/main.cpp3
-rw-r--r--examples/widgets/graphicsview/diagramscene/main.cpp3
-rw-r--r--examples/widgets/graphicsview/diagramscene/mainwindow.cpp17
-rw-r--r--examples/widgets/graphicsview/diagramscene/mainwindow.h4
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.h2
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.cpp2
-rw-r--r--examples/widgets/itemviews/addressbook/main.cpp3
-rw-r--r--examples/widgets/itemviews/chart/mainwindow.cpp2
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/window.cpp2
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp2
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treemodel.cpp3
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treemodel.cpp3
-rw-r--r--examples/widgets/itemviews/spreadsheet/main.cpp4
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp2
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h4
-rw-r--r--examples/widgets/layouts/basiclayouts/main.cpp4
-rw-r--r--examples/widgets/layouts/dynamiclayouts/main.cpp5
-rw-r--r--examples/widgets/layouts/flowlayout/flowlayout.cpp2
-rw-r--r--examples/widgets/mainwindows/application/main.cpp3
-rw-r--r--examples/widgets/mainwindows/dockwidgets/main.cpp3
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.h2
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.h2
-rw-r--r--examples/widgets/painting/affine/main.cpp4
-rw-r--r--examples/widgets/painting/affine/xform.cpp26
-rw-r--r--examples/widgets/painting/basicdrawing/renderarea.cpp1
-rw-r--r--examples/widgets/painting/concentriccircles/main.cpp3
-rw-r--r--examples/widgets/painting/deform/pathdeform.cpp2
-rw-r--r--examples/widgets/painting/fontsampler/main.cpp3
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp23
-rw-r--r--examples/widgets/painting/gradients/main.cpp3
-rw-r--r--examples/widgets/painting/pathstroke/main.cpp3
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.cpp4
-rw-r--r--examples/widgets/tools/regularexpression/regularexpressiondialog.cpp2
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.cpp2
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.cpp132
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.h2
-rw-r--r--examples/widgets/tools/undo/main.cpp3
-rw-r--r--examples/widgets/tutorials/addressbook/part7/addressbook.cpp2
-rw-r--r--examples/widgets/widgets.pro1
-rw-r--r--examples/widgets/widgets/calculator/main.cpp3
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.cpp2
-rw-r--r--examples/widgets/widgets/elidedlabel/main.cpp3
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.cpp5
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.h6
-rw-r--r--examples/widgets/widgets/icons/mainwindow.cpp28
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.cpp12
-rw-r--r--examples/widgets/widgets/scribble/main.cpp3
-rw-r--r--examples/widgets/widgets/sliders/main.cpp3
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.cpp1
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.cpp8
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.h2
-rw-r--r--examples/widgets/widgets/tablet/mainwindow.cpp6
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.cpp8
-rw-r--r--examples/widgets/widgets/validators/localeselector.cpp2
74 files changed, 973 insertions, 206 deletions
diff --git a/examples/widgets/animation/easing/window.cpp b/examples/widgets/animation/easing/window.cpp
index d1d6348361..378af07535 100644
--- a/examples/widgets/animation/easing/window.cpp
+++ b/examples/widgets/animation/easing/window.cpp
@@ -67,7 +67,7 @@ Window::Window(QWidget *parent)
connect(m_ui.easingCurvePicker, &QListWidget::currentRowChanged,
this, &Window::curveChanged);
- connect(m_ui.buttonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
+ connect(m_ui.buttonGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked),
this, &Window::pathChanged);
connect(m_ui.periodSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &Window::periodChanged);
@@ -180,9 +180,10 @@ void Window::curveChanged(int row)
m_ui.overshootSpinBox->setEnabled(curveType >= QEasingCurve::InBack && curveType <= QEasingCurve::OutInBack);
}
-void Window::pathChanged(int index)
+void Window::pathChanged(QAbstractButton *button)
{
- m_anim->setPathType((Animation::PathType)index);
+ const int index = m_ui.buttonGroup->id(button);
+ m_anim->setPathType(Animation::PathType(index));
}
void Window::periodChanged(double value)
diff --git a/examples/widgets/animation/easing/window.h b/examples/widgets/animation/easing/window.h
index 541377a981..0c49dd6e8a 100644
--- a/examples/widgets/animation/easing/window.h
+++ b/examples/widgets/animation/easing/window.h
@@ -69,7 +69,7 @@ public:
Window(QWidget *parent = nullptr);
private slots:
void curveChanged(int row);
- void pathChanged(int index);
+ void pathChanged(QAbstractButton *button);
void periodChanged(double);
void amplitudeChanged(double);
void overshootChanged(double);
diff --git a/examples/widgets/desktop/screenshot/screenshot.cpp b/examples/widgets/desktop/screenshot/screenshot.cpp
index ce5597bbdd..d0a849e0b8 100644
--- a/examples/widgets/desktop/screenshot/screenshot.cpp
+++ b/examples/widgets/desktop/screenshot/screenshot.cpp
@@ -109,7 +109,7 @@ void Screenshot::resizeEvent(QResizeEvent * /* event */)
{
QSize scaledSize = originalPixmap.size();
scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio);
- if (!screenshotLabel->pixmap() || scaledSize != screenshotLabel->pixmap()->size())
+ if (scaledSize != screenshotLabel->pixmap(Qt::ReturnByValue).size())
updateScreenshotLabel();
}
//! [1]
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp
index df77d03567..cd7e8085a2 100644
--- a/examples/widgets/dialogs/standarddialogs/dialog.cpp
+++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp
@@ -329,7 +329,8 @@ void Dialog::setDouble()
//! [1]
bool ok;
double d = QInputDialog::getDouble(this, tr("QInputDialog::getDouble()"),
- tr("Amount:"), 37.56, -10000, 10000, 2, &ok);
+ tr("Amount:"), 37.56, -10000, 10000, 2, &ok,
+ Qt::WindowFlags(), 1);
if (ok)
doubleLabel->setText(QString("$%1").arg(d));
//! [1]
@@ -492,7 +493,7 @@ void Dialog::questionMessage()
void Dialog::warningMessage()
{
QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"),
- MESSAGE, nullptr, this);
+ MESSAGE, { }, this);
msgBox.setDetailedText(MESSAGE_DETAILS);
msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole);
msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole);
diff --git a/examples/widgets/doc/dropsite.qdoc b/examples/widgets/doc/dropsite.qdoc
index af8766a308..d8d09612f6 100644
--- a/examples/widgets/doc/dropsite.qdoc
+++ b/examples/widgets/doc/dropsite.qdoc
@@ -176,16 +176,16 @@
\snippet draganddrop/dropsite/dropsitewindow.cpp constructor part3
- Two QPushButton objects, \c clearButton and \c quitButton, are instantiated
- and added to \c buttonBox - a QDialogButtonBox object. We use
- QDialogButtonBox here to ensure that the push buttons are presented in a
+ Three QPushButton objects, \c clearButton, \c copyButton, and \c quitButton,
+ are instantiated and added to \c buttonBox - a QDialogButtonBox object. We
+ use QDialogButtonBox here to ensure that the push buttons are presented in a
layout that conforms to the platform's style.
\snippet draganddrop/dropsite/dropsitewindow.cpp constructor part4
- The \l{QPushButton::clicked()}{clicked()} signals for \c quitButton and
- \c clearButton are connected to \l{QWidget::close()}{close()} and
- \c clear(), respectively.
+ The \l{QPushButton::clicked()}{clicked()} signals for \c copyButton,
+ \c clearButton, and \c quitButton are connected to \c copy(),
+ \c clear() and \l{QWidget::close()}{close()}, respectively.
For the layout, we use a QVBoxLayout, \c mainLayout, to arrange our widgets
vertically. We also set the window title to "Drop Site" and the minimum
diff --git a/examples/widgets/doc/src/gallery.qdoc b/examples/widgets/doc/src/gallery.qdoc
new file mode 100644
index 0000000000..455099ddce
--- /dev/null
+++ b/examples/widgets/doc/src/gallery.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example gallery
+ \title Widgets Gallery Example
+ \ingroup examples-widgets
+ \brief The Widgets Gallery example shows widgets relevant for designing UIs.
+
+ This example demonstrates widgets typically used in dialogs and forms.
+ It also allows for changing the style.
+*/
diff --git a/examples/widgets/doc/src/icons.qdoc b/examples/widgets/doc/src/icons.qdoc
index 7aae0491d6..24be09a7a9 100644
--- a/examples/widgets/doc/src/icons.qdoc
+++ b/examples/widgets/doc/src/icons.qdoc
@@ -232,8 +232,8 @@
combinations of states and modes for a given icon.
\li \c IconSizeSpinBox is a subclass of QSpinBox that lets the
user enter icon sizes (e.g., "48 x 48").
- \li \c ImageDelegate is a subclass of QItemDelegate that provides
- comboboxes for letting the user set the mode and state
+ \li \c ImageDelegate is a subclass of QStyledItemDelegate that
+ provides comboboxes for letting the user set the mode and state
associated with an image.
\endlist
@@ -468,7 +468,6 @@
loaded into the application.
\snippet widgets/icons/mainwindow.cpp 13
- \snippet widgets/icons/mainwindow.cpp 14
We retrieve the image name using the QFileInfo::baseName()
function that returns the base name of the file without the path,
@@ -486,8 +485,6 @@
Qt::ItemIsEditable flag. Table items are editable by default.
\snippet widgets/icons/mainwindow.cpp 15
- \snippet widgets/icons/mainwindow.cpp 16
- \snippet widgets/icons/mainwindow.cpp 17
Then we create the second and third items in the row making the
default mode Normal and the default state Off. But if the \uicontrol
@@ -498,7 +495,6 @@
example's \c images subdirectory respect this naming convention.
\snippet widgets/icons/mainwindow.cpp 18
- \snippet widgets/icons/mainwindow.cpp 19
In the end we add the items to the associated row, and use the
QTableWidget::openPersistentEditor() function to create
@@ -522,8 +518,6 @@
application.
\snippet widgets/icons/mainwindow.cpp 8
- \snippet widgets/icons/mainwindow.cpp 9
- \snippet widgets/icons/mainwindow.cpp 10
We also extract the image file's name using the
QTableWidgetItem::data() function. This function takes a
@@ -571,24 +565,22 @@
delegate for the table widget. We create a \c ImageDelegate that
we make the item delegate for our view.
- The QItemDelegate class can be used to provide an editor for an item view
+ The QStyledItemDelegate class can be used to provide an editor for an item view
class that is subclassed from QAbstractItemView. Using a delegate
for this purpose allows the editing mechanism to be customized and
developed independently from the model and view.
- In this example we derive \c ImageDelegate from QItemDelegate.
- QItemDelegate usually provides line editors, while our subclass
+ In this example we derive \c ImageDelegate from QStyledItemDelegate.
+ QStyledItemDelegate usually provides line editors, while our subclass
\c ImageDelegate, provides comboboxes for the mode and state
fields.
\snippet widgets/icons/mainwindow.cpp 22
- \snippet widgets/icons/mainwindow.cpp 23
Then we customize the QTableWidget's horizontal header, and hide
the vertical header.
\snippet widgets/icons/mainwindow.cpp 24
- \snippet widgets/icons/mainwindow.cpp 25
At the end, we connect the QTableWidget::itemChanged() signal to
the \c changeIcon() slot to ensure that the preview area is in
@@ -750,23 +742,23 @@
\snippet widgets/icons/imagedelegate.h 0
- The \c ImageDelegate class is a subclass of QItemDelegate. The
- QItemDelegate class provides display and editing facilities for
- data items from a model. A single QItemDelegate object is
+ The \c ImageDelegate class is a subclass of QStyledItemDelegate. The
+ QStyledItemDelegate class provides display and editing facilities for
+ data items from a model. A single QStyledItemDelegate object is
responsible for all items displayed in a item view (in our case,
a QTableWidget).
- A QItemDelegate can be used to provide an editor for an item view
+ A QStyledItemDelegate can be used to provide an editor for an item view
class that is subclassed from QAbstractItemView. Using a delegate
for this purpose allows the editing mechanism to be customized and
developed independently from the model and view.
\snippet widgets/icons/imagedelegate.h 1
- The default implementation of QItemDelegate creates a QLineEdit.
+ The default implementation of QStyledItemDelegate creates a QLineEdit.
Since we want the editor to be a QComboBox, we need to subclass
- QItemDelegate and reimplement the QItemDelegate::createEditor(),
- QItemDelegate::setEditorData() and QItemDelegate::setModelData()
+ QStyledItemDelegate and reimplement the QStyledItemDelegate::createEditor(),
+ QStyledItemDelegate::setEditorData() and QStyledItemDelegate::setModelData()
functions.
\snippet widgets/icons/imagedelegate.h 2
@@ -783,7 +775,7 @@
\snippet widgets/icons/imagedelegate.cpp 1
- The default QItemDelegate::createEditor() implementation returns
+ The default QStyledItemDelegate::createEditor() implementation returns
the widget used to edit the item specified by the model and item
index for editing. The parent widget and style option are used to
control the appearance of the editor widget.
@@ -803,7 +795,7 @@
\snippet widgets/icons/imagedelegate.cpp 2
- The QItemDelegate::setEditorData() function is used by
+ The QStyledItemDelegate::setEditorData() function is used by
QTableWidget to transfer data from a QTableWidgetItem to the
editor. The data is stored as a string; we use
QComboBox::findText() to locate it in the combobox.
@@ -816,7 +808,7 @@
\snippet widgets/icons/imagedelegate.cpp 3
- The QItemDelegate::setEditorData() function is used by QTableWidget
+ The QStyledItemDelegate::setEditorData() function is used by QTableWidget
to transfer data back from the editor to the \l{QTableWidgetItem}.
\snippet widgets/icons/imagedelegate.cpp 4
diff --git a/examples/widgets/doc/src/imageviewer.qdoc b/examples/widgets/doc/src/imageviewer.qdoc
index 91b6385356..8cf8c2489e 100644
--- a/examples/widgets/doc/src/imageviewer.qdoc
+++ b/examples/widgets/doc/src/imageviewer.qdoc
@@ -175,8 +175,8 @@
will expand to
\code
- if (!imageLabel->pixmap())
- qFatal("ASSERT: "imageLabel->pixmap()" in file ...");
+ if (imageLabel->pixmap(Qt::ReturnByValue).isNull())
+ qFatal("ASSERT: "imageLabel->pixmap(Qt::ReturnByValue).isNull()" in file ...");
\endcode
In release mode, the macro simply disappear. The mode can be set
diff --git a/examples/widgets/doc/src/styles.qdoc b/examples/widgets/doc/src/styles.qdoc
index 7a7ae20e91..014541a330 100644
--- a/examples/widgets/doc/src/styles.qdoc
+++ b/examples/widgets/doc/src/styles.qdoc
@@ -27,7 +27,6 @@
/*!
\example widgets/styles
- \meta {tag} {gallery}
\title Styles Example
\ingroup examples-widgets
\brief The Styles example illustrates how to create custom widget
diff --git a/examples/widgets/draganddrop/draggableicons/dragwidget.cpp b/examples/widgets/draganddrop/draggableicons/dragwidget.cpp
index 2019645c1d..00671dcf7e 100644
--- a/examples/widgets/draganddrop/draggableicons/dragwidget.cpp
+++ b/examples/widgets/draganddrop/draggableicons/dragwidget.cpp
@@ -142,7 +142,7 @@ void DragWidget::mousePressEvent(QMouseEvent *event)
if (!child)
return;
- QPixmap pixmap = *child->pixmap();
+ QPixmap pixmap = child->pixmap(Qt::ReturnByValue);
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
index 2135ba2ef9..4a430ebf56 100644
--- a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
+++ b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
@@ -113,7 +113,7 @@ void DragWidget::dropEvent(QDropEvent *event)
if (event->mimeData()->hasText()) {
const QMimeData *mime = event->mimeData();
QStringList pieces = mime->text().split(QRegularExpression(QStringLiteral("\\s+")),
- QString::SkipEmptyParts);
+ Qt::SkipEmptyParts);
QPoint position = event->pos();
QPoint hotSpot;
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
index 2dae83bb22..a937e24a4c 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
@@ -82,14 +82,21 @@ DropSiteWindow::DropSiteWindow()
//! [constructor part4]
clearButton = new QPushButton(tr("Clear"));
+ copyButton = new QPushButton(tr("Copy"));
quitButton = new QPushButton(tr("Quit"));
buttonBox = new QDialogButtonBox;
buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(copyButton, QDialogButtonBox::ActionRole);
+#if !QT_CONFIG(clipboard)
+ copyButton->setVisible(false);
+#endif
+
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close);
connect(clearButton, &QAbstractButton::clicked, dropArea, &DropArea::clear);
+ connect(copyButton, &QAbstractButton::clicked, this, &DropSiteWindow::copy);
//! [constructor part4]
//! [constructor part5]
@@ -108,6 +115,7 @@ DropSiteWindow::DropSiteWindow()
void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
{
formatsTable->setRowCount(0);
+ copyButton->setEnabled(false);
if (!mimeData)
return;
//! [updateFormatsTable() part1]
@@ -145,5 +153,18 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
}
formatsTable->resizeColumnToContents(0);
+#if QT_CONFIG(clipboard)
+ copyButton->setEnabled(formatsTable->rowCount() > 0);
+#endif
}
//! [updateFormatsTable() part4]
+
+void DropSiteWindow::copy()
+{
+#if QT_CONFIG(clipboard)
+ QString text;
+ for (int row = 0, rowCount = formatsTable->rowCount(); row < rowCount; ++row)
+ text += formatsTable->item(row, 0)->text() + ": " + formatsTable->item(row, 1)->text() + '\n';
+ QGuiApplication::clipboard()->setText(text);
+#endif
+}
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.h b/examples/widgets/draganddrop/dropsite/dropsitewindow.h
index d80476f369..a40b481637 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.h
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.h
@@ -72,6 +72,7 @@ public:
public slots:
void updateFormatsTable(const QMimeData *mimeData);
+ void copy();
private:
DropArea *dropArea;
@@ -79,6 +80,7 @@ private:
QTableWidget *formatsTable;
QPushButton *clearButton;
+ QPushButton *copyButton;
QPushButton *quitButton;
QDialogButtonBox *buttonBox;
};
diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
index 451b53f623..a02b1cb42a 100644
--- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
+++ b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
@@ -163,8 +163,8 @@ void DragWidget::dropEvent(QDropEvent *event)
}
//! [11] //! [12]
} else if (event->mimeData()->hasText()) {
- QStringList pieces = event->mimeData()->text().split(QRegularExpression(QStringLiteral("\\s+")),
- QString::SkipEmptyParts);
+ QStringList pieces = event->mimeData()->text().split(
+ QRegularExpression(QStringLiteral("\\s+")), Qt::SkipEmptyParts);
QPoint position = event->pos();
for (const QString &piece : pieces) {
@@ -208,7 +208,7 @@ void DragWidget::mousePressEvent(QMouseEvent *event)
//! [16]
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
- drag->setPixmap(*child->pixmap());
+ drag->setPixmap(child->pixmap(Qt::ReturnByValue));
drag->setHotSpot(hotSpot);
child->hide();
diff --git a/examples/widgets/gallery/gallery.pro b/examples/widgets/gallery/gallery.pro
new file mode 100644
index 0000000000..38bf8d6d8e
--- /dev/null
+++ b/examples/widgets/gallery/gallery.pro
@@ -0,0 +1,10 @@
+QT += widgets
+requires(qtConfig(combobox))
+
+HEADERS = widgetgallery.h
+SOURCES = main.cpp \
+ widgetgallery.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/gallery
+INSTALLS += target
diff --git a/examples/widgets/gallery/main.cpp b/examples/widgets/gallery/main.cpp
new file mode 100644
index 0000000000..7f1782c84e
--- /dev/null
+++ b/examples/widgets/gallery/main.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "widgetgallery.h"
+
+int main(int argc, char *argv[])
+{
+ bool useHighDpiScaling = true;
+
+ for (int i = 1; i < argc; ++i) {
+ if (qstrcmp(argv[i], "--no-scaling") == 0)
+ useHighDpiScaling = false;
+ }
+
+ if (useHighDpiScaling) {
+ QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
+ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ } else {
+ QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
+ }
+
+ QApplication app(argc, argv);
+ WidgetGallery gallery;
+ gallery.show();
+ return QCoreApplication::exec();
+}
diff --git a/examples/widgets/gallery/widgetgallery.cpp b/examples/widgets/gallery/widgetgallery.cpp
new file mode 100644
index 0000000000..3bbe8943d1
--- /dev/null
+++ b/examples/widgets/gallery/widgetgallery.cpp
@@ -0,0 +1,474 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "widgetgallery.h"
+
+#include <QApplication>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QCommandLinkButton>
+#include <QDateTimeEdit>
+#include <QDial>
+#include <QDialogButtonBox>
+#include <QFileSystemModel>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QMenu>
+#include <QLabel>
+#include <QLineEdit>
+#include <QListWidget>
+#include <QPlainTextEdit>
+#include <QProgressBar>
+#include <QPushButton>
+#include <QRadioButton>
+#include <QScrollBar>
+#include <QShortcut>
+#include <QSpinBox>
+#include <QStandardItemModel>
+#include <QStyle>
+#include <QStyleFactory>
+#include <QTextBrowser>
+#include <QTreeView>
+#include <QTableWidget>
+#include <QTextEdit>
+#include <QToolBox>
+#include <QToolButton>
+
+#include <QIcon>
+#include <QDesktopServices>
+#include <QScreen>
+#include <QWindow>
+
+#include <QDebug>
+#include <QLibraryInfo>
+#include <QSysInfo>
+#include <QTextStream>
+#include <QTimer>
+
+static inline QString className(const QObject *o)
+{
+ return QString::fromUtf8(o->metaObject()->className());
+}
+
+static inline void setClassNameToolTip(QWidget *w)
+{
+ w->setToolTip(className(w));
+}
+
+static QString helpUrl(const QString &page)
+{
+ QString result;
+ QTextStream(&result) << "https://doc.qt.io/qt-" << QT_VERSION_MAJOR
+ << '/' << page << ".html";
+ return result;
+}
+
+static inline QString helpUrl(const QWidget *w)
+{
+ return helpUrl(className(w).toLower());
+}
+
+static void launchHelp(const QWidget *w)
+{
+ QDesktopServices::openUrl(helpUrl(w));
+}
+
+static void launchModuleHelp()
+{
+ QDesktopServices::openUrl(helpUrl(QLatin1String("qtwidgets-index")));
+}
+
+template <class Widget>
+Widget *createWidget(const char *name, QWidget *parent = nullptr)
+{
+ auto result = new Widget(parent);
+ result->setObjectName(QLatin1String(name));
+ setClassNameToolTip(result);
+ return result;
+}
+
+template <class Widget, class Parameter>
+Widget *createWidget1(const Parameter &p1, const char *name, QWidget *parent = nullptr)
+{
+ auto result = new Widget(p1, parent);
+ result->setObjectName(QLatin1String(name));
+ setClassNameToolTip(result);
+ return result;
+}
+
+QTextStream &operator<<(QTextStream &str, const QRect &r)
+{
+ str << r.width() << 'x' << r.height() << Qt::forcesign << r.x() << r.y()
+ << Qt::noforcesign;
+ return str;
+}
+
+static QString highDpiScaleFactorRoundingPolicy()
+{
+ QString result;
+ QDebug(&result) << QGuiApplication::highDpiScaleFactorRoundingPolicy();
+ if (result.endsWith(QLatin1Char(')')))
+ result.chop(1);
+ const int lastSep = result.lastIndexOf(QLatin1String("::"));
+ if (lastSep != -1)
+ result.remove(0, lastSep + 2);
+ return result;
+}
+
+WidgetGallery::WidgetGallery(QWidget *parent)
+ : QDialog(parent)
+ , progressBar(createProgressBar())
+{
+ setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+
+ auto styleComboBox = createWidget<QComboBox>("styleComboBox");
+ const QString defaultStyleName = QApplication::style()->objectName();
+ QStringList styleNames = QStyleFactory::keys();
+ for (int i = 1, size = styleNames.size(); i < size; ++i) {
+ if (defaultStyleName.compare(styleNames.at(i), Qt::CaseInsensitive) == 0) {
+ styleNames.swapItemsAt(0, i);
+ break;
+ }
+ }
+ styleComboBox->addItems(styleNames);
+
+ auto styleLabel = createWidget1<QLabel>(tr("&Style:"), "styleLabel");
+ styleLabel->setBuddy(styleComboBox);
+
+ auto helpLabel = createWidget1<QLabel>(tr("Press F1 over a widget to see Documentation"), "helpLabel");
+
+ auto disableWidgetsCheckBox = createWidget1<QCheckBox>(tr("&Disable widgets"), "disableWidgetsCheckBox");
+
+ auto buttonsGroupBox = createButtonsGroupBox();
+ auto itemViewTabWidget = createItemViewTabWidget();
+ auto simpleInputWidgetsGroupBox = createSimpleInputWidgetsGroupBox();
+ auto textToolBox = createTextToolBox();
+
+ connect(styleComboBox, &QComboBox::textActivated,
+ this, &WidgetGallery::changeStyle);
+ connect(disableWidgetsCheckBox, &QCheckBox::toggled,
+ buttonsGroupBox, &QWidget::setDisabled);
+ connect(disableWidgetsCheckBox, &QCheckBox::toggled,
+ textToolBox, &QWidget::setDisabled);
+ connect(disableWidgetsCheckBox, &QCheckBox::toggled,
+ itemViewTabWidget, &QWidget::setDisabled);
+ connect(disableWidgetsCheckBox, &QCheckBox::toggled,
+ simpleInputWidgetsGroupBox, &QWidget::setDisabled);
+
+ auto topLayout = new QHBoxLayout;
+ topLayout->addWidget(styleLabel);
+ topLayout->addWidget(styleComboBox);
+ topLayout->addStretch(1);
+ topLayout->addWidget(helpLabel);
+ topLayout->addStretch(1);
+ topLayout->addWidget(disableWidgetsCheckBox);
+
+ auto dialogButtonBox = createWidget1<QDialogButtonBox>(QDialogButtonBox::Help | QDialogButtonBox::Close,
+ "dialogButtonBox");
+ connect(dialogButtonBox, &QDialogButtonBox::helpRequested, this, launchModuleHelp);
+ connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
+
+ auto mainLayout = new QGridLayout(this);
+ mainLayout->addLayout(topLayout, 0, 0, 1, 2);
+ mainLayout->addWidget(buttonsGroupBox, 1, 0);
+ mainLayout->addWidget(simpleInputWidgetsGroupBox, 1, 1);
+ mainLayout->addWidget(itemViewTabWidget, 2, 0);
+ mainLayout->addWidget(textToolBox, 2, 1);
+ mainLayout->addWidget(progressBar, 3, 0, 1, 2);
+ mainLayout->addWidget(dialogButtonBox, 4, 0, 1, 2);
+
+ setWindowTitle(tr("Widget Gallery Qt %1").arg(QT_VERSION_STR));
+
+ new QShortcut(QKeySequence::HelpContents, this, this, &WidgetGallery::helpOnCurrentWidget);
+}
+
+void WidgetGallery::setVisible(bool visible)
+{
+ QDialog::setVisible(visible);
+ if (visible) {
+ connect(windowHandle(), &QWindow::screenChanged, this, &WidgetGallery::updateSystemInfo);
+ updateSystemInfo();
+ }
+}
+
+void WidgetGallery::changeStyle(const QString &styleName)
+{
+ QApplication::setStyle(QStyleFactory::create(styleName));
+}
+
+void WidgetGallery::advanceProgressBar()
+{
+ int curVal = progressBar->value();
+ int maxVal = progressBar->maximum();
+ progressBar->setValue(curVal + (maxVal - curVal) / 100);
+}
+
+QGroupBox *WidgetGallery::createButtonsGroupBox()
+{
+ auto result = createWidget1<QGroupBox>(tr("Buttons"), "buttonsGroupBox");
+
+ auto defaultPushButton = createWidget1<QPushButton>(tr("Default Push Button"), "defaultPushButton");
+ defaultPushButton->setDefault(true);
+
+ auto togglePushButton = createWidget1<QPushButton>(tr("Toggle Push Button"), "togglePushButton");
+ togglePushButton->setCheckable(true);
+ togglePushButton->setChecked(true);
+
+ auto flatPushButton = createWidget1<QPushButton>(tr("Flat Push Button"), "flatPushButton");
+ flatPushButton->setFlat(true);
+
+ auto toolButton = createWidget<QToolButton>("toolButton");
+ toolButton->setText(tr("Tool Button"));
+
+ auto menuToolButton = createWidget<QToolButton>("menuButton");
+ menuToolButton->setText(tr("Menu Button"));
+ auto toolMenu = new QMenu(menuToolButton);
+ menuToolButton->setPopupMode(QToolButton::InstantPopup);
+ toolMenu->addAction("Option");
+ toolMenu->addSeparator();
+ auto action = toolMenu->addAction("Checkable Option");
+ action->setCheckable(true);
+ menuToolButton->setMenu(toolMenu);
+ auto toolLayout = new QHBoxLayout;
+ toolLayout->addWidget(toolButton);
+ toolLayout->addWidget(menuToolButton);
+
+ auto commandLinkButton = createWidget1<QCommandLinkButton>(tr("Command Link Button"), "commandLinkButton");
+ commandLinkButton->setDescription(tr("Description"));
+
+ auto buttonLayout = new QVBoxLayout;
+ buttonLayout->addWidget(defaultPushButton);
+ buttonLayout->addWidget(togglePushButton);
+ buttonLayout->addWidget(flatPushButton);
+ buttonLayout->addLayout(toolLayout);
+ buttonLayout->addWidget(commandLinkButton);
+ buttonLayout->addStretch(1);
+
+ auto radioButton1 = createWidget1<QRadioButton>(tr("Radio button 1"), "radioButton1");
+ auto radioButton2 = createWidget1<QRadioButton>(tr("Radio button 2"), "radioButton2");
+ auto radioButton3 = createWidget1<QRadioButton>(tr("Radio button 3"), "radioButton3");
+ radioButton1->setChecked(true);
+
+ auto checkBox = createWidget1<QCheckBox>(tr("Tri-state check box"), "checkBox");
+ checkBox->setTristate(true);
+ checkBox->setCheckState(Qt::PartiallyChecked);
+
+ auto checkableLayout = new QVBoxLayout;
+ checkableLayout->addWidget(radioButton1);
+ checkableLayout->addWidget(radioButton2);
+ checkableLayout->addWidget(radioButton3);
+ checkableLayout->addWidget(checkBox);
+ checkableLayout->addStretch(1);
+
+ auto mainLayout = new QHBoxLayout(result);
+ mainLayout->addLayout(buttonLayout);
+ mainLayout->addLayout(checkableLayout);
+ mainLayout->addStretch();
+ return result;
+}
+
+static QWidget *embedIntoHBoxLayout(QWidget *w, int margin = 5)
+{
+ auto result = new QWidget;
+ auto layout = new QHBoxLayout(result);
+ layout->setContentsMargins(margin, margin, margin, margin);
+ layout->addWidget(w);
+ return result;
+}
+
+QToolBox *WidgetGallery::createTextToolBox()
+{
+ auto result = createWidget<QToolBox>("toolBox");
+
+ const QString plainText = tr("Twinkle, twinkle, little star,\n"
+ "How I wonder what you are.\n"
+ "Up above the world so high,\n"
+ "Like a diamond in the sky.\n"
+ "Twinkle, twinkle, little star,\n"
+ "How I wonder what you are!\n");
+ // Create centered/italic HTML rich text
+ QString richText = QLatin1String("<html><head/><body><i>");
+ for (const auto &line : plainText.splitRef(QLatin1Char('\n')))
+ richText += QLatin1String("<center>") + line + QLatin1String("</center>");
+ richText += QLatin1String("</i></body></html>");
+
+ auto textEdit = createWidget1<QTextEdit>(richText, "textEdit");
+ auto plainTextEdit = createWidget1<QPlainTextEdit>(plainText, "plainTextEdit");
+
+ systemInfoTextBrowser = createWidget<QTextBrowser>("systemInfoTextBrowser");
+
+ result->addItem(embedIntoHBoxLayout(textEdit), tr("Text Edit"));
+ result->addItem(embedIntoHBoxLayout(plainTextEdit), tr("Plain Text Edit"));
+ result->addItem(embedIntoHBoxLayout(systemInfoTextBrowser), tr("Text Browser"));
+ return result;
+}
+
+QTabWidget *WidgetGallery::createItemViewTabWidget()
+{
+ auto result = createWidget<QTabWidget>("bottomLeftTabWidget");
+ result->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
+
+ auto treeView = createWidget<QTreeView>("treeView");
+ auto fileSystemModel = new QFileSystemModel(treeView);
+ fileSystemModel->setRootPath(QDir::rootPath());
+ treeView->setModel(fileSystemModel);
+
+ auto tableWidget = createWidget<QTableWidget>("tableWidget");
+ tableWidget->setRowCount(10);
+ tableWidget->setColumnCount(10);
+
+ auto listModel = new QStandardItemModel(0, 1, result);
+ listModel->appendRow(new QStandardItem(QIcon(QLatin1String(":/qt-project.org/styles/commonstyle/images/diropen-128.png")),
+ tr("Directory")));
+ listModel->appendRow(new QStandardItem(QIcon(QLatin1String(":/qt-project.org/styles/commonstyle/images/computer-32.png")),
+ tr("Computer")));
+
+ auto listView = createWidget<QListView>("listView");
+ listView->setModel(listModel);
+
+ auto iconModeListView = createWidget<QListView>("iconModeListView");
+ iconModeListView->setViewMode(QListView::IconMode);
+ iconModeListView->setModel(listModel);
+
+ result->addTab(embedIntoHBoxLayout(treeView), tr("&Tree View"));
+ result->addTab(embedIntoHBoxLayout(tableWidget), tr("T&able"));
+ result->addTab(embedIntoHBoxLayout(listView), tr("&List"));
+ result->addTab(embedIntoHBoxLayout(iconModeListView), tr("&Icon Mode List"));
+ return result;
+}
+
+QGroupBox *WidgetGallery::createSimpleInputWidgetsGroupBox()
+{
+ auto result = createWidget1<QGroupBox>(tr("Simple Input Widgets"), "bottomRightGroupBox");
+ result->setCheckable(true);
+ result->setChecked(true);
+
+ auto lineEdit = createWidget1<QLineEdit>("s3cRe7", "lineEdit");
+ lineEdit->setClearButtonEnabled(true);
+ lineEdit->setEchoMode(QLineEdit::Password);
+
+ auto spinBox = createWidget<QSpinBox>("spinBox", result);
+ spinBox->setValue(50);
+
+ auto dateTimeEdit = createWidget<QDateTimeEdit>("dateTimeEdit", result);
+ dateTimeEdit->setDateTime(QDateTime::currentDateTime());
+
+ auto slider = createWidget<QSlider>("slider", result);
+ slider->setOrientation(Qt::Horizontal);
+ slider->setValue(40);
+
+ auto scrollBar = createWidget<QScrollBar>("scrollBar", result);
+ scrollBar->setOrientation(Qt::Horizontal);
+ setClassNameToolTip(scrollBar);
+ scrollBar->setValue(60);
+
+ auto dial = createWidget<QDial>("dial", result);
+ dial->setValue(30);
+ dial->setNotchesVisible(true);
+
+ auto layout = new QGridLayout(result);
+ layout->addWidget(lineEdit, 0, 0, 1, 2);
+ layout->addWidget(spinBox, 1, 0, 1, 2);
+ layout->addWidget(dateTimeEdit, 2, 0, 1, 2);
+ layout->addWidget(slider, 3, 0);
+ layout->addWidget(scrollBar, 4, 0);
+ layout->addWidget(dial, 3, 1, 2, 1);
+ layout->setRowStretch(5, 1);
+ return result;
+}
+
+QProgressBar *WidgetGallery::createProgressBar()
+{
+ auto result = createWidget<QProgressBar>("progressBar");
+ result->setRange(0, 10000);
+ result->setValue(0);
+
+ auto timer = new QTimer(this);
+ connect(timer, &QTimer::timeout, this, &WidgetGallery::advanceProgressBar);
+ timer->start(1000);
+ return result;
+}
+
+void WidgetGallery::updateSystemInfo()
+{
+ QString systemInfo;
+ QTextStream str(&systemInfo);
+ str << "<html><head/><body><h3>Build</h3><p>" << QLibraryInfo::build() << "</p>"
+ << "<h3>Operating System</h3><p>" << QSysInfo::prettyProductName() << "</p>"
+ << "<h3>Screens</h3><p>High DPI scale factor rounding policy: "
+ << highDpiScaleFactorRoundingPolicy() << "</p><ol>";
+ const auto screens = QGuiApplication::screens();
+ for (auto screen : screens) {
+ const bool current = screen == this->screen();
+ str << "<li>";
+ if (current)
+ str << "<i>";
+ str << '"' << screen->name() << "\" " << screen->geometry() << ", "
+ << screen->logicalDotsPerInchX() << "DPI, DPR="
+ << screen->devicePixelRatio();
+ if (current)
+ str << "</i>";
+ str << "</li>";
+ }
+ str << "</ol></body></html>";
+ systemInfoTextBrowser->setHtml(systemInfo);
+}
+
+void WidgetGallery::helpOnCurrentWidget()
+{
+ // Skip over internal widgets
+ for (auto w = QApplication::widgetAt(QCursor::pos(screen())); w; w = w->parentWidget()) {
+ const QString name = w->objectName();
+ if (!name.isEmpty() && !name.startsWith(QLatin1String("qt_"))) {
+ launchHelp(w);
+ break;
+ }
+ }
+}
diff --git a/examples/widgets/gallery/widgetgallery.h b/examples/widgets/gallery/widgetgallery.h
new file mode 100644
index 0000000000..419c925190
--- /dev/null
+++ b/examples/widgets/gallery/widgetgallery.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WIDGETGALLERY_H
+#define WIDGETGALLERY_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QGroupBox;
+class QProgressBar;
+class QTabWidget;
+class QTextBrowser;
+class QToolBox;
+QT_END_NAMESPACE
+
+class WidgetGallery : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit WidgetGallery(QWidget *parent = nullptr);
+
+ void setVisible(bool visible) override;
+
+private slots:
+ void changeStyle(const QString &styleName);
+ void advanceProgressBar();
+ void helpOnCurrentWidget();
+ void updateSystemInfo();
+
+private:
+ static QGroupBox *createButtonsGroupBox();
+ static QTabWidget *createItemViewTabWidget();
+ static QGroupBox *createSimpleInputWidgetsGroupBox();
+ QToolBox *createTextToolBox();
+ QProgressBar *createProgressBar();
+
+ QProgressBar *progressBar;
+ QTextBrowser *systemInfoTextBrowser;
+};
+
+#endif // WIDGETGALLERY_H
diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h
index 5d65dc71e2..31bc3d7b66 100644
--- a/examples/widgets/graphicsview/boxes/scene.h
+++ b/examples/widgets/graphicsview/boxes/scene.h
@@ -215,7 +215,6 @@ private:
void initGL();
QPointF pixelPosToViewPos(const QPointF& p);
- QTime m_time; // ### Qt 6: remove (unused)
int m_lastTime;
int m_mouseEventTime;
int m_distExp;
diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp
index d6fec778c2..3b1718bdbd 100644
--- a/examples/widgets/graphicsview/chip/view.cpp
+++ b/examples/widgets/graphicsview/chip/view.cpp
@@ -234,11 +234,11 @@ void View::setupMatrix()
{
qreal scale = qPow(qreal(2), (zoomSlider->value() - 250) / qreal(50));
- QMatrix matrix;
+ QTransform matrix;
matrix.scale(scale, scale);
matrix.rotate(rotateSlider->value());
- graphicsView->setMatrix(matrix);
+ graphicsView->setTransform(matrix);
setResetButtonEnabled();
}
diff --git a/examples/widgets/graphicsview/collidingmice/main.cpp b/examples/widgets/graphicsview/collidingmice/main.cpp
index ef6d6cca64..c9ad90260f 100644
--- a/examples/widgets/graphicsview/collidingmice/main.cpp
+++ b/examples/widgets/graphicsview/collidingmice/main.cpp
@@ -58,6 +58,9 @@ static constexpr int MouseCount = 7;
//! [0]
int main(int argc, char **argv)
{
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
//! [0]
diff --git a/examples/widgets/graphicsview/diagramscene/main.cpp b/examples/widgets/graphicsview/diagramscene/main.cpp
index eefaa86554..3e321259c5 100644
--- a/examples/widgets/graphicsview/diagramscene/main.cpp
+++ b/examples/widgets/graphicsview/diagramscene/main.cpp
@@ -55,6 +55,9 @@
int main(int argv, char *args[])
{
Q_INIT_RESOURCE(diagramscene);
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argv, args);
MainWindow mainWindow;
diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
index 3327d4d5df..58b959dd10 100644
--- a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
+++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
@@ -113,13 +113,14 @@ void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button)
//! [1]
//! [2]
-void MainWindow::buttonGroupClicked(int id)
+void MainWindow::buttonGroupClicked(QAbstractButton *button)
{
const QList<QAbstractButton *> buttons = buttonGroup->buttons();
- for (QAbstractButton *button : buttons) {
- if (buttonGroup->button(id) != button)
+ for (QAbstractButton *myButton : buttons) {
+ if (myButton != button)
button->setChecked(false);
}
+ const int id = buttonGroup->id(button);
if (id == InsertTextButton) {
scene->setMode(DiagramScene::InsertText);
} else {
@@ -154,7 +155,7 @@ void MainWindow::deleteItem()
//! [3]
//! [4]
-void MainWindow::pointerGroupClicked(int)
+void MainWindow::pointerGroupClicked()
{
scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId()));
}
@@ -231,8 +232,8 @@ void MainWindow::fontSizeChanged(const QString &)
void MainWindow::sceneScaleChanged(const QString &scale)
{
double newScale = scale.left(scale.indexOf(tr("%"))).toDouble() / 100.0;
- QMatrix oldMatrix = view->matrix();
- view->resetMatrix();
+ QTransform oldMatrix = view->transform();
+ view->resetTransform();
view->translate(oldMatrix.dx(), oldMatrix.dy());
view->scale(newScale, newScale);
}
@@ -334,7 +335,7 @@ void MainWindow::createToolBox()
{
buttonGroup = new QButtonGroup(this);
buttonGroup->setExclusive(false);
- connect(buttonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
+ connect(buttonGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked),
this, &MainWindow::buttonGroupClicked);
QGridLayout *layout = new QGridLayout;
layout->addWidget(createCellWidget(tr("Conditional"), DiagramItem::Conditional), 0, 0);
@@ -528,7 +529,7 @@ void MainWindow::createToolbars()
pointerTypeGroup = new QButtonGroup(this);
pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem));
pointerTypeGroup->addButton(linePointerButton, int(DiagramScene::InsertLine));
- connect(pointerTypeGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
+ connect(pointerTypeGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked),
this, &MainWindow::pointerGroupClicked);
sceneScaleCombo = new QComboBox;
diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.h b/examples/widgets/graphicsview/diagramscene/mainwindow.h
index e04224fbc7..9fcd1884ca 100644
--- a/examples/widgets/graphicsview/diagramscene/mainwindow.h
+++ b/examples/widgets/graphicsview/diagramscene/mainwindow.h
@@ -82,9 +82,9 @@ public:
private slots:
void backgroundButtonGroupClicked(QAbstractButton *button);
- void buttonGroupClicked(int id);
+ void buttonGroupClicked(QAbstractButton *button);
void deleteItem();
- void pointerGroupClicked(int id);
+ void pointerGroupClicked();
void bringToFront();
void sendToBack();
void itemInserted(DiagramItem *item);
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
index d7df2b7b4b..5aa0250a29 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
+++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
@@ -59,7 +59,7 @@ class CustomProxy : public QGraphicsProxyWidget
Q_OBJECT
public:
- explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = nullptr);
+ explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = { });
QRectF boundingRect() const override;
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
diff --git a/examples/widgets/graphicsview/flowlayout/window.cpp b/examples/widgets/graphicsview/flowlayout/window.cpp
index 8fe06d0e11..0edaa686b4 100644
--- a/examples/widgets/graphicsview/flowlayout/window.cpp
+++ b/examples/widgets/graphicsview/flowlayout/window.cpp
@@ -59,7 +59,7 @@ Window::Window(QGraphicsItem *parent) : QGraphicsWidget(parent, Qt::Window)
FlowLayout *lay = new FlowLayout;
const QString sentence(QLatin1String("I am not bothered by the fact that I am unknown."
" I am bothered when I do not know others. (Confucius)"));
- const QVector<QStringRef> words = sentence.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
+ const QVector<QStringRef> words = sentence.splitRef(QLatin1Char(' '), Qt::SkipEmptyParts);
for (const QStringRef &word : words) {
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
QLabel *label = new QLabel(word.toString());
diff --git a/examples/widgets/itemviews/addressbook/main.cpp b/examples/widgets/itemviews/addressbook/main.cpp
index 0731287cdd..86a11c5850 100644
--- a/examples/widgets/itemviews/addressbook/main.cpp
+++ b/examples/widgets/itemviews/addressbook/main.cpp
@@ -55,6 +55,9 @@
//! [0]
int main(int argc, char *argv[])
{
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
MainWindow mw;
mw.show();
diff --git a/examples/widgets/itemviews/chart/mainwindow.cpp b/examples/widgets/itemviews/chart/mainwindow.cpp
index 53f57fbb49..671cfb1941 100644
--- a/examples/widgets/itemviews/chart/mainwindow.cpp
+++ b/examples/widgets/itemviews/chart/mainwindow.cpp
@@ -134,7 +134,7 @@ void MainWindow::loadFile(const QString &fileName)
if (!line.isEmpty()) {
model->insertRows(row, 1, QModelIndex());
- const QStringList pieces = line.split(',', QString::SkipEmptyParts);
+ const QStringList pieces = line.split(QLatin1Char(','), Qt::SkipEmptyParts);
if (pieces.size() < 3)
continue;
model->setData(model->index(row, 0, QModelIndex()),
diff --git a/examples/widgets/itemviews/coloreditorfactory/window.cpp b/examples/widgets/itemviews/coloreditorfactory/window.cpp
index e4a9379d8f..25e196a80c 100644
--- a/examples/widgets/itemviews/coloreditorfactory/window.cpp
+++ b/examples/widgets/itemviews/coloreditorfactory/window.cpp
@@ -61,7 +61,7 @@ Window::Window()
QItemEditorCreatorBase *colorListCreator =
new QStandardItemEditorCreator<ColorListEditor>();
- factory->registerEditor(QVariant::Color, colorListCreator);
+ factory->registerEditor(QMetaType::QColor, colorListCreator);
QItemEditorFactory::setDefaultFactory(factory);
diff --git a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
index 430a086fd6..fd17876f2b 100644
--- a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
+++ b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
@@ -98,7 +98,7 @@ bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
//! [4]
//! [6]
- if (leftData.type() == QVariant::DateTime) {
+ if (leftData.userType() == QMetaType::QDateTime) {
return leftData.toDateTime() < rightData.toDateTime();
} else {
static const QRegularExpression emailPattern("[\\w\\.]*@[\\w\\.]*");
diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
index 836c2e8651..9678e45be7 100644
--- a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
+++ b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
@@ -267,7 +267,8 @@ void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
if (!lineData.isEmpty()) {
// Read the column data from the rest of the line.
- const QStringList columnStrings = lineData.split('\t', QString::SkipEmptyParts);
+ const QStringList columnStrings =
+ lineData.split(QLatin1Char('\t'), Qt::SkipEmptyParts);
QVector<QVariant> columnData;
columnData.reserve(columnStrings.size());
for (const QString &columnString : columnStrings)
diff --git a/examples/widgets/itemviews/simpletreemodel/treemodel.cpp b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
index cfa65846ed..28640d6433 100644
--- a/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
+++ b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
@@ -194,7 +194,8 @@ void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
if (!lineData.isEmpty()) {
// Read the column data from the rest of the line.
- const QStringList columnStrings = lineData.split('\t', QString::SkipEmptyParts);
+ const QStringList columnStrings =
+ lineData.split(QLatin1Char('\t'), Qt::SkipEmptyParts);
QVector<QVariant> columnData;
columnData.reserve(columnStrings.count());
for (const QString &columnString : columnStrings)
diff --git a/examples/widgets/itemviews/spreadsheet/main.cpp b/examples/widgets/itemviews/spreadsheet/main.cpp
index 548dc8d604..968312d097 100644
--- a/examples/widgets/itemviews/spreadsheet/main.cpp
+++ b/examples/widgets/itemviews/spreadsheet/main.cpp
@@ -56,6 +56,10 @@
int main(int argc, char **argv)
{
Q_INIT_RESOURCE(spreadsheet);
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
+
QApplication app(argc, argv);
SpreadSheet sheet(10, 6);
sheet.setWindowIcon(QPixmap(":/images/interview.png"));
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
index eadd5fadb8..ad80a238aa 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
@@ -53,7 +53,7 @@
#include <QtWidgets>
SpreadSheetDelegate::SpreadSheetDelegate(QObject *parent)
- : QItemDelegate(parent)
+ : QStyledItemDelegate(parent)
{}
QWidget *SpreadSheetDelegate::createEditor(QWidget *parent,
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
index c89459cadf..36c70d2391 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
@@ -51,9 +51,9 @@
#ifndef SPREADSHEETDELEGATE_H
#define SPREADSHEETDELEGATE_H
-#include <QItemDelegate>
+#include <QStyledItemDelegate>
-class SpreadSheetDelegate : public QItemDelegate
+class SpreadSheetDelegate : public QStyledItemDelegate
{
Q_OBJECT
diff --git a/examples/widgets/layouts/basiclayouts/main.cpp b/examples/widgets/layouts/basiclayouts/main.cpp
index f59de1d385..cf0ff0a535 100644
--- a/examples/widgets/layouts/basiclayouts/main.cpp
+++ b/examples/widgets/layouts/basiclayouts/main.cpp
@@ -56,7 +56,11 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Dialog dialog;
+#ifdef Q_OS_ANDROID
+ dialog.showMaximized();
+#else
dialog.show();
+#endif
return app.exec();
}
diff --git a/examples/widgets/layouts/dynamiclayouts/main.cpp b/examples/widgets/layouts/dynamiclayouts/main.cpp
index 9959c472f4..cf0ff0a535 100644
--- a/examples/widgets/layouts/dynamiclayouts/main.cpp
+++ b/examples/widgets/layouts/dynamiclayouts/main.cpp
@@ -56,6 +56,11 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Dialog dialog;
+#ifdef Q_OS_ANDROID
+ dialog.showMaximized();
+#else
dialog.show();
+#endif
+
return app.exec();
}
diff --git a/examples/widgets/layouts/flowlayout/flowlayout.cpp b/examples/widgets/layouts/flowlayout/flowlayout.cpp
index 5c59ae025c..9a488557cf 100644
--- a/examples/widgets/layouts/flowlayout/flowlayout.cpp
+++ b/examples/widgets/layouts/flowlayout/flowlayout.cpp
@@ -123,7 +123,7 @@ QLayoutItem *FlowLayout::takeAt(int index)
//! [6]
Qt::Orientations FlowLayout::expandingDirections() const
{
- return 0;
+ return { };
}
//! [6]
diff --git a/examples/widgets/mainwindows/application/main.cpp b/examples/widgets/mainwindows/application/main.cpp
index 78db7134a3..b46e1116dc 100644
--- a/examples/widgets/mainwindows/application/main.cpp
+++ b/examples/widgets/mainwindows/application/main.cpp
@@ -58,6 +58,9 @@
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(application);
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
QCoreApplication::setOrganizationName("QtProject");
diff --git a/examples/widgets/mainwindows/dockwidgets/main.cpp b/examples/widgets/mainwindows/dockwidgets/main.cpp
index ff3ba506a8..bf3ad9bcf7 100644
--- a/examples/widgets/mainwindows/dockwidgets/main.cpp
+++ b/examples/widgets/mainwindows/dockwidgets/main.cpp
@@ -54,6 +54,9 @@
int main(int argc, char *argv[])
{
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
Q_INIT_RESOURCE(dockwidgets);
MainWindow mainWin;
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.h b/examples/widgets/mainwindows/mainwindow/colorswatch.h
index 7f73e46f31..2bd9fd2891 100644
--- a/examples/widgets/mainwindows/mainwindow/colorswatch.h
+++ b/examples/widgets/mainwindows/mainwindow/colorswatch.h
@@ -62,7 +62,7 @@ class ColorSwatch : public QDockWidget
Q_OBJECT
public:
- explicit ColorSwatch(const QString &colorName, QMainWindow *parent = nullptr, Qt::WindowFlags flags = 0);
+ explicit ColorSwatch(const QString &colorName, QMainWindow *parent = nullptr, Qt::WindowFlags flags = { });
void setCustomSizeHint(const QSize &size);
QMenu *colorSwatchMenu() const { return menu; }
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.h b/examples/widgets/mainwindows/mainwindow/mainwindow.h
index a2c9d30ded..3ce9732763 100644
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.h
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.h
@@ -65,7 +65,7 @@ public:
explicit MainWindow(const CustomSizeHintMap &customSizeHints,
QWidget *parent = nullptr,
- Qt::WindowFlags flags = 0);
+ Qt::WindowFlags flags = { });
public slots:
void actionTriggered(QAction *action);
diff --git a/examples/widgets/painting/affine/main.cpp b/examples/widgets/painting/affine/main.cpp
index 6ce8efe482..641fc5c204 100644
--- a/examples/widgets/painting/affine/main.cpp
+++ b/examples/widgets/painting/affine/main.cpp
@@ -55,7 +55,9 @@
int main(int argc, char **argv)
{
Q_INIT_RESOURCE(affine);
-
+#ifdef Q_OS_ANDROID
+ qputenv("QT_SCALE_FACTOR", "2");
+#endif
QApplication app(argc, argv);
XFormWidget xformWidget(nullptr);
diff --git a/examples/widgets/painting/affine/xform.cpp b/examples/widgets/painting/affine/xform.cpp
index 50acf0f814..d7ed2125d2 100644
--- a/examples/widgets/painting/affine/xform.cpp
+++ b/examples/widgets/painting/affine/xform.cpp
@@ -223,7 +223,7 @@ void XFormView::setRotation(qreal r)
m_rotation = r;
QPointF center(pts->points().at(0));
- QMatrix m;
+ QTransform m;
m.translate(center.x(), center.y());
m.rotate(m_rotation - old_rot);
m.translate(-center.x(), -center.y());
@@ -236,7 +236,7 @@ void XFormView::timerEvent(QTimerEvent *e)
{
if (e->timerId() == timer.timerId()) {
QPointF center(pts->points().at(0));
- QMatrix m;
+ QTransform m;
m.translate(center.x(), center.y());
m.rotate(0.2);
m.translate(-center.x(), -center.y());
@@ -787,8 +787,8 @@ XFormWidget::XFormWidget(QWidget *parent)
view = new XFormView(this);
view->setMinimumSize(200, 200);
- QGroupBox *mainGroup = new QGroupBox(this);
- mainGroup->setFixedWidth(180);
+ QWidget *mainContentWidget = new QWidget();
+ QGroupBox *mainGroup = new QGroupBox(mainContentWidget);
mainGroup->setTitle(tr("Affine Transformations"));
QGroupBox *rotateGroup = new QGroupBox(mainGroup);
@@ -837,10 +837,6 @@ XFormWidget::XFormWidget(QWidget *parent)
whatsThisButton->setText(tr("What's This?"));
whatsThisButton->setCheckable(true);
- QHBoxLayout *viewLayout = new QHBoxLayout(this);
- viewLayout->addWidget(view);
- viewLayout->addWidget(mainGroup);
-
QVBoxLayout *rotateGroupLayout = new QVBoxLayout(rotateGroup);
rotateGroupLayout->addWidget(rotateSlider);
@@ -871,6 +867,20 @@ XFormWidget::XFormWidget(QWidget *parent)
#endif
mainGroupLayout->addWidget(whatsThisButton);
+ mainGroup->setLayout(mainGroupLayout);
+
+ QVBoxLayout *mainContentLayout = new QVBoxLayout();
+ mainContentLayout->addWidget(mainGroup);
+ mainContentWidget->setLayout(mainContentLayout);
+
+ QScrollArea *mainScrollArea = new QScrollArea();
+ mainScrollArea->setWidget(mainContentWidget);
+ mainScrollArea->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
+
+ QHBoxLayout *viewLayout = new QHBoxLayout(this);
+ viewLayout->addWidget(view);
+ viewLayout->addWidget(mainScrollArea);
+
connect(rotateSlider, &QSlider::valueChanged, view, &XFormView::changeRotation);
connect(shearSlider, &QSlider::valueChanged, view, &XFormView::changeShear);
connect(scaleSlider, &QSlider::valueChanged, view, &XFormView::changeScale);
diff --git a/examples/widgets/painting/basicdrawing/renderarea.cpp b/examples/widgets/painting/basicdrawing/renderarea.cpp
index a1437dea8f..09d610ee95 100644
--- a/examples/widgets/painting/basicdrawing/renderarea.cpp
+++ b/examples/widgets/painting/basicdrawing/renderarea.cpp
@@ -51,6 +51,7 @@
#include "renderarea.h"
#include <QPainter>
+#include <QPainterPath>
//! [0]
RenderArea::RenderArea(QWidget *parent)
diff --git a/examples/widgets/painting/concentriccircles/main.cpp b/examples/widgets/painting/concentriccircles/main.cpp
index d9fa2879c4..00456195d9 100644
--- a/examples/widgets/painting/concentriccircles/main.cpp
+++ b/examples/widgets/painting/concentriccircles/main.cpp
@@ -54,6 +54,9 @@
int main(int argc, char *argv[])
{
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
Window window;
window.show();
diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp
index d5c8746247..961d5e5e99 100644
--- a/examples/widgets/painting/deform/pathdeform.cpp
+++ b/examples/widgets/painting/deform/pathdeform.cpp
@@ -374,7 +374,7 @@ void PathDeformRenderer::setText(const QString &text)
}
for (int i=0; i<m_paths.size(); ++i)
- m_paths[i] = m_paths[i] * QMatrix(1, 0, 0, 1, -m_pathBounds.x(), -m_pathBounds.y());
+ m_paths[i] = m_paths[i] * QTransform(1, 0, 0, 1, -m_pathBounds.x(), -m_pathBounds.y());
update();
}
diff --git a/examples/widgets/painting/fontsampler/main.cpp b/examples/widgets/painting/fontsampler/main.cpp
index 1bf46b226f..cec6929827 100644
--- a/examples/widgets/painting/fontsampler/main.cpp
+++ b/examples/widgets/painting/fontsampler/main.cpp
@@ -54,6 +54,9 @@
int main(int argc, char *argv[])
{
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
MainWindow window;
window.show();
diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp
index d62ae93a15..cb1a0177e9 100644
--- a/examples/widgets/painting/gradients/gradients.cpp
+++ b/examples/widgets/painting/gradients/gradients.cpp
@@ -282,7 +282,8 @@ GradientWidget::GradientWidget(QWidget *parent)
m_renderer = new GradientRenderer(this);
- QGroupBox *mainGroup = new QGroupBox(this);
+ QWidget *mainContentWidget = new QWidget();
+ QGroupBox *mainGroup = new QGroupBox(mainContentWidget);
mainGroup->setTitle(tr("Gradients"));
QGroupBox *editorGroup = new QGroupBox(mainGroup);
@@ -327,11 +328,6 @@ GradientWidget::GradientWidget(QWidget *parent)
whatsThisButton->setText(tr("What's This?"));
whatsThisButton->setCheckable(true);
- // Layouts
- QHBoxLayout *mainLayout = new QHBoxLayout(this);
- mainLayout->addWidget(m_renderer);
- mainLayout->addWidget(mainGroup);
-
mainGroup->setFixedWidth(200);
QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
mainGroupLayout->addWidget(editorGroup);
@@ -370,6 +366,21 @@ GradientWidget::GradientWidget(QWidget *parent)
defaultsGroupLayout->addWidget(default3Button);
editorGroupLayout->addWidget(default4Button);
+ mainGroup->setLayout(mainGroupLayout);
+
+ QVBoxLayout *mainContentLayout = new QVBoxLayout();
+ mainContentLayout->addWidget(mainGroup);
+ mainContentWidget->setLayout(mainContentLayout);
+
+ QScrollArea *mainScrollArea = new QScrollArea();
+ mainScrollArea->setWidget(mainContentWidget);
+ mainScrollArea->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
+
+ // Layouts
+ QHBoxLayout *mainLayout = new QHBoxLayout(this);
+ mainLayout->addWidget(m_renderer);
+ mainLayout->addWidget(mainScrollArea);
+
connect(m_editor, &GradientEditor::gradientStopsChanged,
m_renderer, &GradientRenderer::setGradientStops);
connect(m_linearButton, &QRadioButton::clicked,
diff --git a/examples/widgets/painting/gradients/main.cpp b/examples/widgets/painting/gradients/main.cpp
index 0ddf7a4579..7ffb0326e9 100644
--- a/examples/widgets/painting/gradients/main.cpp
+++ b/examples/widgets/painting/gradients/main.cpp
@@ -55,6 +55,9 @@
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(gradients);
+#ifdef Q_OS_ANDROID
+ qputenv("QT_SCALE_FACTOR", "2");
+#endif
QApplication app(argc, argv);
diff --git a/examples/widgets/painting/pathstroke/main.cpp b/examples/widgets/painting/pathstroke/main.cpp
index 57c85d73a3..35317480a3 100644
--- a/examples/widgets/painting/pathstroke/main.cpp
+++ b/examples/widgets/painting/pathstroke/main.cpp
@@ -55,6 +55,9 @@
int main(int argc, char **argv)
{
Q_INIT_RESOURCE(pathstroke);
+#ifdef Q_OS_ANDROID
+ qputenv("QT_SCALE_FACTOR", "2");
+#endif
QApplication app(argc, argv);
diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp
index a850ce2672..7dab6f95a2 100644
--- a/examples/widgets/painting/pathstroke/pathstroke.cpp
+++ b/examples/widgets/painting/pathstroke/pathstroke.cpp
@@ -511,10 +511,10 @@ void PathStrokeRenderer::initializePoints()
m_points.clear();
m_vectors.clear();
- QMatrix m;
+ QTransform m;
qreal rot = 360.0 / count;
QPointF center(width() / 2, height() / 2);
- QMatrix vm;
+ QTransform vm;
vm.shear(2, -1);
vm.scale(3, 3);
diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp
index ea3cb00a02..6398098eee 100644
--- a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp
+++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp
@@ -286,7 +286,7 @@ void RegularExpressionDialog::refresh()
setResultUiEnabled(true);
- QRegularExpression::MatchType matchType = matchTypeComboBox->currentData().value<QRegularExpression::MatchType>();
+ QRegularExpression::MatchType matchType = qvariant_cast<QRegularExpression::MatchType>(matchTypeComboBox->currentData());
QRegularExpression::PatternOptions patternOptions = QRegularExpression::NoPatternOption;
QRegularExpression::MatchOptions matchOptions = QRegularExpression::NoMatchOption;
diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp
index 49d299bf72..9132368e4a 100644
--- a/examples/widgets/tools/settingseditor/settingstree.cpp
+++ b/examples/widgets/tools/settingseditor/settingstree.cpp
@@ -208,7 +208,7 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
}
QVariant value = settings->value(key);
- if (value.type() == QVariant::Invalid) {
+ if (value.userType() == QMetaType::UnknownType) {
child->setText(1, "Invalid");
} else {
child->setText(1, value.typeName());
diff --git a/examples/widgets/tools/settingseditor/variantdelegate.cpp b/examples/widgets/tools/settingseditor/variantdelegate.cpp
index 9772fe8a41..eb822f0dc2 100644
--- a/examples/widgets/tools/settingseditor/variantdelegate.cpp
+++ b/examples/widgets/tools/settingseditor/variantdelegate.cpp
@@ -81,7 +81,7 @@ void VariantDelegate::paint(QPainter *painter,
{
if (index.column() == 2) {
QVariant value = index.model()->data(index, Qt::UserRole);
- if (!isSupportedType(value.type())) {
+ if (!isSupportedType(value.userType())) {
QStyleOptionViewItem myOption = option;
myOption.state &= ~QStyle::State_Enabled;
QStyledItemDelegate::paint(painter, myOption, index);
@@ -100,7 +100,7 @@ QWidget *VariantDelegate::createEditor(QWidget *parent,
return nullptr;
QVariant originalValue = index.model()->data(index, Qt::UserRole);
- if (!isSupportedType(originalValue.type()))
+ if (!isSupportedType(originalValue.userType()))
return nullptr;
QLineEdit *lineEdit = new QLineEdit(parent);
@@ -108,46 +108,46 @@ QWidget *VariantDelegate::createEditor(QWidget *parent,
QRegularExpression regExp;
- switch (originalValue.type()) {
- case QVariant::Bool:
+ switch (originalValue.userType()) {
+ case QMetaType::Bool:
regExp = boolExp;
break;
- case QVariant::ByteArray:
+ case QMetaType::QByteArray:
regExp = byteArrayExp;
break;
- case QVariant::Char:
+ case QMetaType::QChar:
regExp = charExp;
break;
- case QVariant::Color:
+ case QMetaType::QColor:
regExp = colorExp;
break;
- case QVariant::Date:
+ case QMetaType::QDate:
regExp = dateExp;
break;
- case QVariant::DateTime:
+ case QMetaType::QDateTime:
regExp = dateTimeExp;
break;
- case QVariant::Double:
+ case QMetaType::Double:
regExp = doubleExp;
break;
- case QVariant::Int:
- case QVariant::LongLong:
+ case QMetaType::Int:
+ case QMetaType::LongLong:
regExp = signedIntegerExp;
break;
- case QVariant::Point:
+ case QMetaType::QPoint:
regExp = pointExp;
break;
- case QVariant::Rect:
+ case QMetaType::QRect:
regExp = rectExp;
break;
- case QVariant::Size:
+ case QMetaType::QSize:
regExp = sizeExp;
break;
- case QVariant::Time:
+ case QMetaType::QTime:
regExp = timeExp;
break;
- case QVariant::UInt:
- case QVariant::ULongLong:
+ case QMetaType::UInt:
+ case QMetaType::ULongLong:
regExp = unsignedIntegerExp;
break;
default:
@@ -189,18 +189,18 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
QVariant value;
QRegularExpressionMatch match;
- switch (originalValue.type()) {
- case QVariant::Char:
+ switch (originalValue.userType()) {
+ case QMetaType::QChar:
value = text.at(0);
break;
- case QVariant::Color:
+ case QMetaType::QColor:
match = colorExp.match(text);
value = QColor(qMin(match.captured(1).toInt(), 255),
qMin(match.captured(2).toInt(), 255),
qMin(match.captured(3).toInt(), 255),
qMin(match.captured(4).toInt(), 255));
break;
- case QVariant::Date:
+ case QMetaType::QDate:
{
QDate date = QDate::fromString(text, Qt::ISODate);
if (!date.isValid())
@@ -208,7 +208,7 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
value = date;
}
break;
- case QVariant::DateTime:
+ case QMetaType::QDateTime:
{
QDateTime dateTime = QDateTime::fromString(text, Qt::ISODate);
if (!dateTime.isValid())
@@ -216,23 +216,23 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
value = dateTime;
}
break;
- case QVariant::Point:
+ case QMetaType::QPoint:
match = pointExp.match(text);
value = QPoint(match.captured(1).toInt(), match.captured(2).toInt());
break;
- case QVariant::Rect:
+ case QMetaType::QRect:
match = rectExp.match(text);
value = QRect(match.captured(1).toInt(), match.captured(2).toInt(),
match.captured(3).toInt(), match.captured(4).toInt());
break;
- case QVariant::Size:
+ case QMetaType::QSize:
match = sizeExp.match(text);
value = QSize(match.captured(1).toInt(), match.captured(2).toInt());
break;
- case QVariant::StringList:
+ case QMetaType::QStringList:
value = text.split(',');
break;
- case QVariant::Time:
+ case QMetaType::QTime:
{
QTime time = QTime::fromString(text, Qt::ISODate);
if (!time.isValid())
@@ -242,33 +242,33 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
break;
default:
value = text;
- value.convert(originalValue.type());
+ value.convert(originalValue.userType());
}
model->setData(index, displayText(value), Qt::DisplayRole);
model->setData(index, value, Qt::UserRole);
}
-bool VariantDelegate::isSupportedType(QVariant::Type type)
+bool VariantDelegate::isSupportedType(int type)
{
switch (type) {
- case QVariant::Bool:
- case QVariant::ByteArray:
- case QVariant::Char:
- case QVariant::Color:
- case QVariant::Date:
- case QVariant::DateTime:
- case QVariant::Double:
- case QVariant::Int:
- case QVariant::LongLong:
- case QVariant::Point:
- case QVariant::Rect:
- case QVariant::Size:
- case QVariant::String:
- case QVariant::StringList:
- case QVariant::Time:
- case QVariant::UInt:
- case QVariant::ULongLong:
+ case QMetaType::Bool:
+ case QMetaType::QByteArray:
+ case QMetaType::QChar:
+ case QMetaType::QColor:
+ case QMetaType::QDate:
+ case QMetaType::QDateTime:
+ case QMetaType::Double:
+ case QMetaType::Int:
+ case QMetaType::LongLong:
+ case QMetaType::QPoint:
+ case QMetaType::QRect:
+ case QMetaType::QSize:
+ case QMetaType::QString:
+ case QMetaType::QStringList:
+ case QMetaType::QTime:
+ case QMetaType::UInt:
+ case QMetaType::ULongLong:
return true;
default:
return false;
@@ -277,50 +277,50 @@ bool VariantDelegate::isSupportedType(QVariant::Type type)
QString VariantDelegate::displayText(const QVariant &value)
{
- switch (value.type()) {
- case QVariant::Bool:
- case QVariant::ByteArray:
- case QVariant::Char:
- case QVariant::Double:
- case QVariant::Int:
- case QVariant::LongLong:
- case QVariant::String:
- case QVariant::UInt:
- case QVariant::ULongLong:
+ switch (value.userType()) {
+ case QMetaType::Bool:
+ case QMetaType::QByteArray:
+ case QMetaType::QChar:
+ case QMetaType::Double:
+ case QMetaType::Int:
+ case QMetaType::LongLong:
+ case QMetaType::QString:
+ case QMetaType::UInt:
+ case QMetaType::ULongLong:
return value.toString();
- case QVariant::Color:
+ case QMetaType::QColor:
{
QColor color = qvariant_cast<QColor>(value);
return QString("(%1,%2,%3,%4)")
.arg(color.red()).arg(color.green())
.arg(color.blue()).arg(color.alpha());
}
- case QVariant::Date:
+ case QMetaType::QDate:
return value.toDate().toString(Qt::ISODate);
- case QVariant::DateTime:
+ case QMetaType::QDateTime:
return value.toDateTime().toString(Qt::ISODate);
- case QVariant::Invalid:
+ case QMetaType::UnknownType:
return "<Invalid>";
- case QVariant::Point:
+ case QMetaType::QPoint:
{
QPoint point = value.toPoint();
return QString("(%1,%2)").arg(point.x()).arg(point.y());
}
- case QVariant::Rect:
+ case QMetaType::QRect:
{
QRect rect = value.toRect();
return QString("(%1,%2,%3,%4)")
.arg(rect.x()).arg(rect.y())
.arg(rect.width()).arg(rect.height());
}
- case QVariant::Size:
+ case QMetaType::QSize:
{
QSize size = value.toSize();
return QString("(%1,%2)").arg(size.width()).arg(size.height());
}
- case QVariant::StringList:
+ case QMetaType::QStringList:
return value.toStringList().join(',');
- case QVariant::Time:
+ case QMetaType::QTime:
return value.toTime().toString(Qt::ISODate);
default:
break;
diff --git a/examples/widgets/tools/settingseditor/variantdelegate.h b/examples/widgets/tools/settingseditor/variantdelegate.h
index 68f21fa3f6..96e44fd181 100644
--- a/examples/widgets/tools/settingseditor/variantdelegate.h
+++ b/examples/widgets/tools/settingseditor/variantdelegate.h
@@ -69,7 +69,7 @@ public:
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const override;
- static bool isSupportedType(QVariant::Type type);
+ static bool isSupportedType(int type);
static QString displayText(const QVariant &value);
private:
diff --git a/examples/widgets/tools/undo/main.cpp b/examples/widgets/tools/undo/main.cpp
index a5ec1b1b83..1a6dcf8c48 100644
--- a/examples/widgets/tools/undo/main.cpp
+++ b/examples/widgets/tools/undo/main.cpp
@@ -54,6 +54,9 @@
int main(int argc, char **argv)
{
Q_INIT_RESOURCE(undo);
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
diff --git a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp
index 717d0882af..1ba23756c4 100644
--- a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp
+++ b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp
@@ -413,7 +413,7 @@ void AddressBook::exportAsVCard()
int index = name.indexOf(" ");
if (index != -1) {
- nameList = name.split(QRegularExpression("\\s+"), QString::SkipEmptyParts);
+ nameList = name.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
firstName = nameList.first();
lastName = nameList.last();
} else {
diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro
index d975ea8307..99e1c71594 100644
--- a/examples/widgets/widgets.pro
+++ b/examples/widgets/widgets.pro
@@ -9,6 +9,7 @@ SUBDIRS = \
dialogs \
draganddrop \
effects \
+ gallery \
gestures \
graphicsview \
itemviews \
diff --git a/examples/widgets/widgets/calculator/main.cpp b/examples/widgets/widgets/calculator/main.cpp
index a034bb262e..5f59d00ca6 100644
--- a/examples/widgets/widgets/calculator/main.cpp
+++ b/examples/widgets/widgets/calculator/main.cpp
@@ -54,6 +54,9 @@
int main(int argc, char *argv[])
{
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
Calculator calc;
calc.show();
diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp
index b0f9705c21..702b50156b 100644
--- a/examples/widgets/widgets/charactermap/mainwindow.cpp
+++ b/examples/widgets/widgets/charactermap/mainwindow.cpp
@@ -201,7 +201,7 @@ void MainWindow::findStyles(const QFont &font)
void MainWindow::filterChanged(int f)
{
const QFontComboBox::FontFilter filter =
- filterCombo->itemData(f).value<QFontComboBox::FontFilter>();
+ qvariant_cast<QFontComboBox::FontFilter>(filterCombo->itemData(f));
fontCombo->setFontFilters(filter);
statusBar()->showMessage(tr("%n font(s) found", nullptr, fontCombo->count()));
}
diff --git a/examples/widgets/widgets/elidedlabel/main.cpp b/examples/widgets/widgets/elidedlabel/main.cpp
index 1c620c1d41..58507766e7 100644
--- a/examples/widgets/widgets/elidedlabel/main.cpp
+++ b/examples/widgets/widgets/elidedlabel/main.cpp
@@ -55,6 +55,9 @@
//! [0]
int main( int argc, char *argv[] )
{
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication application( argc, argv );
TestWidget w;
w.showFullScreen();
diff --git a/examples/widgets/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp
index 39c2e43134..4fd251aa1b 100644
--- a/examples/widgets/widgets/icons/imagedelegate.cpp
+++ b/examples/widgets/widgets/icons/imagedelegate.cpp
@@ -55,9 +55,8 @@
//! [0]
ImageDelegate::ImageDelegate(QObject *parent)
- : QItemDelegate(parent)
-{
-}
+ : QStyledItemDelegate(parent)
+{}
//! [0]
//! [1]
diff --git a/examples/widgets/widgets/icons/imagedelegate.h b/examples/widgets/widgets/icons/imagedelegate.h
index 3b76b78339..9d65304e2c 100644
--- a/examples/widgets/widgets/icons/imagedelegate.h
+++ b/examples/widgets/widgets/icons/imagedelegate.h
@@ -51,10 +51,10 @@
#ifndef IMAGEDELEGATE_H
#define IMAGEDELEGATE_H
-#include <QItemDelegate>
+#include <QStyledItemDelegate>
//! [0]
-class ImageDelegate : public QItemDelegate
+class ImageDelegate : public QStyledItemDelegate
{
Q_OBJECT
@@ -72,7 +72,7 @@ public:
//! [1] //! [2]
private slots:
void emitCommitData();
-};
//! [2]
+};
#endif
diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp
index f342c18c4c..4f990f7320 100644
--- a/examples/widgets/widgets/icons/mainwindow.cpp
+++ b/examples/widgets/widgets/icons/mainwindow.cpp
@@ -216,16 +216,13 @@ void MainWindow::changeIcon()
QImage image(fileName);
if (!image.isNull())
icon.addPixmap(QPixmap::fromImage(image), mode, state);
-//! [8] //! [9]
+//! [8]
}
-//! [9] //! [10]
}
-//! [10]
-
//! [11]
previewArea->setIcon(icon);
-}
//! [11]
+}
void MainWindow::addSampleImages()
{
@@ -280,17 +277,15 @@ void MainWindow::loadImages(const QStringList &fileNames)
.arg(QDir::toNativeSeparators(fileInfo.absolutePath()), fileInfo.fileName())
.arg(fileInfo2x.exists() ? fileInfo2x.fileName() : tr("<None>"))
.arg(image.width()).arg(image.height());
-//! [13] //! [14]
QTableWidgetItem *fileItem = new QTableWidgetItem(imageName);
fileItem->setData(Qt::UserRole, fileName);
fileItem->setIcon(QPixmap::fromImage(image));
fileItem->setFlags((fileItem->flags() | Qt::ItemIsUserCheckable) & ~Qt::ItemIsEditable);
fileItem->setToolTip(toolTip);
-//! [14]
+//! [13]
//! [15]
QIcon::Mode mode = QIcon::Normal;
-//! [15] //! [16]
QIcon::State state = QIcon::Off;
if (guessModeStateAct->isChecked()) {
if (imageName.contains(QLatin1String("_act"), Qt::CaseInsensitive))
@@ -302,13 +297,11 @@ void MainWindow::loadImages(const QStringList &fileNames)
if (imageName.contains(QLatin1String("_on"), Qt::CaseInsensitive))
state = QIcon::On;
-//! [16] //! [17]
+//! [15]
}
-//! [17]
//! [18]
imagesTable->setItem(row, 0, fileItem);
-//! [18] //! [19]
QTableWidgetItem *modeItem =
new QTableWidgetItem(IconPreviewArea::iconModeNames().at(IconPreviewArea::iconModes().indexOf(mode)));
modeItem->setToolTip(toolTip);
@@ -321,9 +314,9 @@ void MainWindow::loadImages(const QStringList &fileNames)
imagesTable->openPersistentEditor(stateItem);
fileItem->setCheckState(Qt::Checked);
+//! [18]
}
}
-//! [19]
void MainWindow::useHighDpiPixmapsChanged(int checkState)
{
@@ -350,9 +343,7 @@ QWidget *MainWindow::createImagesGroupBox()
//! [21]
//! [22]
- QStringList labels;
-//! [22] //! [23]
- labels << tr("Image") << tr("Mode") << tr("State");
+ const QStringList labels({tr("Image"), tr("Mode"), tr("State")});
imagesTable->horizontalHeader()->setDefaultSectionSize(90);
imagesTable->setColumnCount(3);
@@ -361,18 +352,17 @@ QWidget *MainWindow::createImagesGroupBox()
imagesTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
imagesTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed);
imagesTable->verticalHeader()->hide();
-//! [23]
+//! [22]
//! [24]
connect(imagesTable, &QTableWidget::itemChanged,
-//! [24] //! [25]
this, &MainWindow::changeIcon);
QVBoxLayout *layout = new QVBoxLayout(imagesGroupBox);
layout->addWidget(imagesTable);
return imagesGroupBox;
+//! [24]
}
-//! [25]
//! [26]
QWidget *MainWindow::createIconSizeGroupBox()
@@ -428,8 +418,8 @@ QWidget *MainWindow::createIconSizeGroupBox()
layout->addLayout(otherSizeLayout, 3, 0, 1, 2);
layout->setRowStretch(4, 1);
return iconSizeGroupBox;
-}
//! [27]
+}
void MainWindow::screenChanged()
{
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp
index 1ed55ca6cb..7de0c7c45b 100644
--- a/examples/widgets/widgets/imageviewer/imageviewer.cpp
+++ b/examples/widgets/widgets/imageviewer/imageviewer.cpp
@@ -201,19 +201,20 @@ void ImageViewer::saveAs()
void ImageViewer::print()
//! [5] //! [6]
{
- Q_ASSERT(imageLabel->pixmap());
+ Q_ASSERT(!imageLabel->pixmap(Qt::ReturnByValue).isNull());
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
//! [6] //! [7]
QPrintDialog dialog(&printer, this);
//! [7] //! [8]
if (dialog.exec()) {
QPainter painter(&printer);
+ QPixmap pixmap = imageLabel->pixmap(Qt::ReturnByValue);
QRect rect = painter.viewport();
- QSize size = imageLabel->pixmap()->size();
+ QSize size = pixmap.size();
size.scale(rect.size(), Qt::KeepAspectRatio);
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
- painter.setWindow(imageLabel->pixmap()->rect());
- painter.drawPixmap(0, 0, *imageLabel->pixmap());
+ painter.setWindow(pixmap.rect());
+ painter.drawPixmap(0, 0, pixmap);
}
#endif
}
@@ -384,9 +385,8 @@ void ImageViewer::updateActions()
void ImageViewer::scaleImage(double factor)
//! [23] //! [24]
{
- Q_ASSERT(imageLabel->pixmap());
scaleFactor *= factor;
- imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
+ imageLabel->resize(scaleFactor * imageLabel->pixmap(Qt::ReturnByValue).size());
adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
adjustScrollBar(scrollArea->verticalScrollBar(), factor);
diff --git a/examples/widgets/widgets/scribble/main.cpp b/examples/widgets/widgets/scribble/main.cpp
index 1bf46b226f..cec6929827 100644
--- a/examples/widgets/widgets/scribble/main.cpp
+++ b/examples/widgets/widgets/scribble/main.cpp
@@ -54,6 +54,9 @@
int main(int argc, char *argv[])
{
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
MainWindow window;
window.show();
diff --git a/examples/widgets/widgets/sliders/main.cpp b/examples/widgets/widgets/sliders/main.cpp
index 99725195e5..9bf18cb6d4 100644
--- a/examples/widgets/widgets/sliders/main.cpp
+++ b/examples/widgets/widgets/sliders/main.cpp
@@ -54,6 +54,9 @@
int main(int argc, char *argv[])
{
+#ifdef Q_OS_ANDROID
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
QApplication app(argc, argv);
Window window;
window.show();
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
index 31150cd994..34a63e0eea 100644
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
@@ -52,6 +52,7 @@
#include <QComboBox>
#include <QPainter>
+#include <QPainterPath>
#include <QPushButton>
#include <QStyleFactory>
diff --git a/examples/widgets/widgets/styles/widgetgallery.cpp b/examples/widgets/widgets/styles/widgetgallery.cpp
index d70c503f53..bf8e93feb4 100644
--- a/examples/widgets/widgets/styles/widgetgallery.cpp
+++ b/examples/widgets/widgets/styles/widgetgallery.cpp
@@ -75,8 +75,6 @@
WidgetGallery::WidgetGallery(QWidget *parent)
: QDialog(parent)
{
- originalPalette = QApplication::palette();
-
styleComboBox = new QComboBox;
const QString defaultStyleName = QApplication::style()->objectName();
QStringList styleNames = QStyleFactory::keys();
@@ -162,10 +160,8 @@ void WidgetGallery::changeStyle(const QString &styleName)
void WidgetGallery::changePalette()
//! [7] //! [8]
{
- if (useStylePaletteCheckBox->isChecked())
- QApplication::setPalette(QApplication::style()->standardPalette());
- else
- QApplication::setPalette(originalPalette);
+ QApplication::setPalette(useStylePaletteCheckBox->isChecked() ?
+ QApplication::style()->standardPalette() : QPalette());
}
//! [8]
diff --git a/examples/widgets/widgets/styles/widgetgallery.h b/examples/widgets/widgets/styles/widgetgallery.h
index 4deee6839a..8c4c880536 100644
--- a/examples/widgets/widgets/styles/widgetgallery.h
+++ b/examples/widgets/widgets/styles/widgetgallery.h
@@ -96,8 +96,6 @@ private:
void createBottomRightGroupBox();
void createProgressBar();
- QPalette originalPalette;
-
QLabel *styleLabel;
QComboBox *styleComboBox;
QCheckBox *useStylePaletteCheckBox;
diff --git a/examples/widgets/widgets/tablet/mainwindow.cpp b/examples/widgets/widgets/tablet/mainwindow.cpp
index 8bcb9ada63..c5b631ee44 100644
--- a/examples/widgets/widgets/tablet/mainwindow.cpp
+++ b/examples/widgets/widgets/tablet/mainwindow.cpp
@@ -85,21 +85,21 @@ void MainWindow::setBrushColor()
//! [2]
void MainWindow::setAlphaValuator(QAction *action)
{
- m_canvas->setAlphaChannelValuator(action->data().value<TabletCanvas::Valuator>());
+ m_canvas->setAlphaChannelValuator(qvariant_cast<TabletCanvas::Valuator>(action->data()));
}
//! [2]
//! [3]
void MainWindow::setLineWidthValuator(QAction *action)
{
- m_canvas->setLineWidthType(action->data().value<TabletCanvas::Valuator>());
+ m_canvas->setLineWidthType(qvariant_cast<TabletCanvas::Valuator>(action->data()));
}
//! [3]
//! [4]
void MainWindow::setSaturationValuator(QAction *action)
{
- m_canvas->setColorSaturationValuator(action->data().value<TabletCanvas::Valuator>());
+ m_canvas->setColorSaturationValuator(qvariant_cast<TabletCanvas::Valuator>(action->data()));
}
//! [4]
diff --git a/examples/widgets/widgets/tablet/tabletcanvas.cpp b/examples/widgets/widgets/tablet/tabletcanvas.cpp
index 59ca608cef..90a5017500 100644
--- a/examples/widgets/widgets/tablet/tabletcanvas.cpp
+++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp
@@ -106,7 +106,7 @@ void TabletCanvas::tabletEvent(QTabletEvent *event)
break;
case QEvent::TabletMove:
#ifndef Q_OS_IOS
- if (event->device() == QTabletEvent::RotationStylus)
+ if (event->deviceType() == QTabletEvent::RotationStylus)
updateCursor(event);
#endif
if (m_deviceDown) {
@@ -161,7 +161,7 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
static qreal maxPenRadius = pressureToWidth(1.0);
painter.setRenderHint(QPainter::Antialiasing);
- switch (event->device()) {
+ switch (event->deviceType()) {
//! [6]
case QTabletEvent::Airbrush:
{
@@ -251,7 +251,7 @@ void TabletCanvas::updateBrush(const QTabletEvent *event)
m_color.setAlphaF(event->pressure());
break;
case TangentialPressureValuator:
- if (event->device() == QTabletEvent::Airbrush)
+ if (event->deviceType() == QTabletEvent::Airbrush)
m_color.setAlphaF(qMax(0.01, (event->tangentialPressure() + 1.0) / 2.0));
else
m_color.setAlpha(255);
@@ -312,7 +312,7 @@ void TabletCanvas::updateCursor(const QTabletEvent *event)
if (event->pointerType() == QTabletEvent::Eraser) {
cursor = QCursor(QPixmap(":/images/cursor-eraser.png"), 3, 28);
} else {
- switch (event->device()) {
+ switch (event->deviceType()) {
case QTabletEvent::Stylus:
cursor = QCursor(QPixmap(":/images/cursor-pencil.png"), 0, 0);
break;
diff --git a/examples/widgets/widgets/validators/localeselector.cpp b/examples/widgets/widgets/validators/localeselector.cpp
index 1382da0cc9..3dcd04d9ff 100644
--- a/examples/widgets/widgets/validators/localeselector.cpp
+++ b/examples/widgets/widgets/validators/localeselector.cpp
@@ -90,6 +90,6 @@ void LocaleSelector::emitLocaleSelected(int index)
QVariant v = itemData(index);
if (!v.isValid())
return;
- const QLocale l = v.value<QLocale>();
+ const QLocale l = qvariant_cast<QLocale>(v);
emit localeSelected(l);
}