summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/animation/easing/animation.h4
-rw-r--r--examples/widgets/animation/easing/window.cpp2
-rw-r--r--examples/widgets/animation/easing/window.h5
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.cpp2
-rw-r--r--examples/widgets/doc/dropsite.qdoc4
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.cpp10
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.h3
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.cpp40
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramitem.cpp2
-rw-r--r--examples/widgets/graphicsview/diagramscene/mainwindow.cpp4
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.cpp4
-rw-r--r--examples/widgets/graphicsview/elasticnodes/node.cpp4
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.cpp6
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.h5
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.h5
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.cpp2
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treeitem.cpp4
-rw-r--r--examples/widgets/layouts/basiclayouts/dialog.cpp19
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dialog.cpp2
-rw-r--r--examples/widgets/layouts/flowlayout/flowlayout.cpp4
-rw-r--r--examples/widgets/painting/composition/composition.cpp10
-rw-r--r--examples/widgets/painting/composition/composition.h1
-rw-r--r--examples/widgets/painting/fontsampler/mainwindow.cpp4
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp2
-rw-r--r--examples/widgets/painting/painterpaths/window.cpp10
-rw-r--r--examples/widgets/painting/shared/fbopaintdevice.cpp17
-rw-r--r--examples/widgets/painting/shared/fbopaintdevice.h2
-rw-r--r--examples/widgets/painting/shared/hoverpoints.cpp2
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.cpp2
-rw-r--r--examples/widgets/tutorials/modelview/1_readonly/mymodel.h3
-rw-r--r--examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp8
-rw-r--r--examples/widgets/tutorials/modelview/2_formatting/mymodel.h3
-rw-r--r--examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp4
-rw-r--r--examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h9
-rw-r--r--examples/widgets/tutorials/modelview/4_headers/mymodel.h3
-rw-r--r--examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp11
-rw-r--r--examples/widgets/tutorials/modelview/5_edit/mainwindow.h9
-rw-r--r--examples/widgets/tutorials/modelview/6_treeview/mainwindow.h12
-rw-r--r--examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp32
-rw-r--r--examples/widgets/tutorials/modelview/7_selections/mainwindow.h12
-rw-r--r--examples/widgets/widgets/scribble/mainwindow.cpp2
-rw-r--r--examples/widgets/widgets/sliders/window.cpp41
-rw-r--r--examples/widgets/widgets/sliders/window.h4
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.cpp2
-rw-r--r--examples/widgets/widgets/validators/validatorwidget.h5
45 files changed, 219 insertions, 122 deletions
diff --git a/examples/widgets/animation/easing/animation.h b/examples/widgets/animation/easing/animation.h
index b6b4824583..111ad44f45 100644
--- a/examples/widgets/animation/easing/animation.h
+++ b/examples/widgets/animation/easing/animation.h
@@ -15,8 +15,8 @@ public:
CirclePath,
NPathTypes
};
- Animation(QObject *target, const QByteArray &prop)
- : QPropertyAnimation(target, prop)
+ Animation(QObject *target, const QByteArray &prop, QObject *parent = nullptr)
+ : QPropertyAnimation(target, prop, parent)
{
setPathType(LinearPath);
}
diff --git a/examples/widgets/animation/easing/window.cpp b/examples/widgets/animation/easing/window.cpp
index 260efa7832..11929738ae 100644
--- a/examples/widgets/animation/easing/window.cpp
+++ b/examples/widgets/animation/easing/window.cpp
@@ -35,7 +35,7 @@ Window::Window(QWidget *parent)
m_scene.addItem(m_item);
m_ui.graphicsView->setScene(&m_scene);
- m_anim = new Animation(m_item, "pos");
+ m_anim = new Animation(m_item, "pos", this);
m_anim->setEasingCurve(QEasingCurve::OutBounce);
m_ui.easingCurvePicker->setCurrentRow(int(QEasingCurve::OutBounce));
diff --git a/examples/widgets/animation/easing/window.h b/examples/widgets/animation/easing/window.h
index b454d1853f..ea6bb74667 100644
--- a/examples/widgets/animation/easing/window.h
+++ b/examples/widgets/animation/easing/window.h
@@ -1,6 +1,9 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#ifndef WINDOW_H
+#define WINDOW_H
+
#include <QtWidgets>
#include "ui_form.h"
@@ -37,3 +40,5 @@ private:
Animation *m_anim;
QSize m_iconSize;
};
+
+#endif // WINDOW_H
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp
index 1775a4231a..443101e421 100644
--- a/examples/widgets/dialogs/standarddialogs/dialog.cpp
+++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp
@@ -52,7 +52,7 @@ void DialogOptionsWidget::addSpacer()
int DialogOptionsWidget::value() const
{
int result = 0;
- for (const CheckBoxEntry &checkboxEntry : qAsConst(checkBoxEntries)) {
+ for (const CheckBoxEntry &checkboxEntry : std::as_const(checkBoxEntries)) {
if (checkboxEntry.first->isChecked())
result |= checkboxEntry.second;
}
diff --git a/examples/widgets/doc/dropsite.qdoc b/examples/widgets/doc/dropsite.qdoc
index fb10643f48..5ebf0ff3a4 100644
--- a/examples/widgets/doc/dropsite.qdoc
+++ b/examples/widgets/doc/dropsite.qdoc
@@ -25,8 +25,8 @@
\snippet draganddrop/dropsite/droparea.h DropArea header part1
- In addition, \c DropArea also contains a private instance of QLabel and
- reimplementations of four \l{QWidget} event handlers:
+ In addition, \c DropArea contains reimplementations of four \l{QWidget}
+ event handlers:
\list 1
\li \l{QWidget::dragEnterEvent()}{dragEnterEvent()}
diff --git a/examples/widgets/draganddrop/dropsite/droparea.cpp b/examples/widgets/draganddrop/dropsite/droparea.cpp
index 096f59fe16..1b2ff1820d 100644
--- a/examples/widgets/draganddrop/dropsite/droparea.cpp
+++ b/examples/widgets/draganddrop/dropsite/droparea.cpp
@@ -6,6 +6,8 @@
#include <QDragEnterEvent>
#include <QMimeData>
+using namespace Qt::StringLiterals;
+
//! [DropArea constructor]
DropArea::DropArea(QWidget *parent)
: QLabel(parent)
@@ -46,8 +48,8 @@ void DropArea::dropEvent(QDropEvent *event)
//! [dropEvent() function part2]
if (mimeData->hasImage()) {
setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
- } else if (mimeData->hasFormat(QLatin1String("text/markdown"))) {
- setText(QString::fromUtf8(mimeData->data(QLatin1String("text/markdown"))));
+ } else if (mimeData->hasFormat(u"text/markdown"_s)) {
+ setText(QString::fromUtf8(mimeData->data(u"text/markdown"_s)));
setTextFormat(Qt::MarkdownText);
} else if (mimeData->hasHtml()) {
setText(mimeData->html());
@@ -58,8 +60,8 @@ void DropArea::dropEvent(QDropEvent *event)
} else if (mimeData->hasUrls()) {
QList<QUrl> urlList = mimeData->urls();
QString text;
- for (int i = 0; i < urlList.size() && i < 32; ++i)
- text += urlList.at(i).path() + QLatin1Char('\n');
+ for (qsizetype i = 0, count = qMin(urlList.size(), qsizetype(32)); i < count; ++i)
+ text += urlList.at(i).path() + u'\n';
setText(text);
} else {
setText(tr("Cannot display data"));
diff --git a/examples/widgets/draganddrop/dropsite/droparea.h b/examples/widgets/draganddrop/dropsite/droparea.h
index 507f8d854f..3e5947b236 100644
--- a/examples/widgets/draganddrop/dropsite/droparea.h
+++ b/examples/widgets/draganddrop/dropsite/droparea.h
@@ -31,9 +31,6 @@ protected:
void dragMoveEvent(QDragMoveEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
void dropEvent(QDropEvent *event) override;
-
-private:
- QLabel *label;
};
//! [DropArea header part2]
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
index 0208f76a50..2969fdf7ae 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
@@ -1,11 +1,23 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
+#include <QPushButton>
+#include <QDialogButtonBox>
+#include <QHeaderView>
+#include <QTableWidget>
+#include <QTableWidgetItem>
+#include <QVBoxLayout>
+
+#include <QClipboard>
+#include <QGuiApplication>
+
+#include <QMimeData>
#include "droparea.h"
#include "dropsitewindow.h"
+using namespace Qt::StringLiterals;
+
//! [constructor part1]
DropSiteWindow::DropSiteWindow()
{
@@ -23,13 +35,10 @@ DropSiteWindow::DropSiteWindow()
//! [constructor part2]
//! [constructor part3]
- QStringList labels;
- labels << tr("Format") << tr("Content");
-
formatsTable = new QTableWidget;
formatsTable->setColumnCount(2);
formatsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
- formatsTable->setHorizontalHeaderLabels(labels);
+ formatsTable->setHorizontalHeaderLabels({tr("Format"), tr("Content")});
formatsTable->horizontalHeader()->setStretchLastSection(true);
//! [constructor part3]
@@ -60,7 +69,7 @@ DropSiteWindow::DropSiteWindow()
mainLayout->addWidget(buttonBox);
setWindowTitle(tr("Drop Site"));
- setMinimumSize(350, 500);
+ resize(700, 500);
}
//! [constructor part5]
@@ -83,20 +92,21 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
//! [updateFormatsTable() part3]
QString text;
- if (format == QLatin1String("text/plain")) {
+ if (format == u"text/plain") {
text = mimeData->text().simplified();
- } else if (format == QLatin1String("text/markdown")) {
- text = QString::fromUtf8(mimeData->data(QLatin1String("text/markdown")));
- } else if (format == QLatin1String("text/html")) {
+ } else if (format == u"text/markdown") {
+ text = QString::fromUtf8(mimeData->data(u"text/markdown"_s));
+ } else if (format == u"text/html") {
text = mimeData->html().simplified();
- } else if (format == QLatin1String("text/uri-list")) {
+ } else if (format == u"text/uri-list") {
QList<QUrl> urlList = mimeData->urls();
- for (int i = 0; i < urlList.size() && i < 32; ++i)
- text.append(urlList.at(i).toString() + QLatin1Char(' '));
+ for (qsizetype i = 0, count = qMin(urlList.size(), qsizetype(32)); i < count; ++i)
+ text.append(urlList.at(i).toString() + u' ');
} else {
QByteArray data = mimeData->data(format);
- for (int i = 0; i < data.size() && i < 32; ++i)
- text.append(QStringLiteral("%1 ").arg(uchar(data[i]), 2, 16, QLatin1Char('0')).toUpper());
+ if (data.size() > 32)
+ data.truncate(32);
+ text = QString::fromLatin1(data.toHex(' ')).toUpper();
}
//! [updateFormatsTable() part3]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
index ae764371ae..c7a94f14ec 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
+++ b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
@@ -105,7 +105,7 @@ void DiagramItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QVariant DiagramItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemPositionChange) {
- for (Arrow *arrow : qAsConst(arrows))
+ for (Arrow *arrow : std::as_const(arrows))
arrow->updatePosition();
}
diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
index dc77b500cb..d6a389af38 100644
--- a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
+++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
@@ -87,7 +87,7 @@ void MainWindow::buttonGroupClicked(QAbstractButton *button)
void MainWindow::deleteItem()
{
QList<QGraphicsItem *> selectedItems = scene->selectedItems();
- for (QGraphicsItem *item : qAsConst(selectedItems)) {
+ for (QGraphicsItem *item : std::as_const(selectedItems)) {
if (item->type() == Arrow::Type) {
scene->removeItem(item);
Arrow *arrow = qgraphicsitem_cast<Arrow *>(item);
@@ -98,7 +98,7 @@ void MainWindow::deleteItem()
}
selectedItems = scene->selectedItems();
- for (QGraphicsItem *item : qAsConst(selectedItems)) {
+ for (QGraphicsItem *item : std::as_const(selectedItems)) {
if (item->type() == DiagramItem::Type)
qgraphicsitem_cast<DiagramItem *>(item)->removeArrows();
scene->removeItem(item);
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
index 3d8ca8e972..ede3d23137 100644
--- a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
@@ -123,11 +123,11 @@ void GraphWidget::timerEvent(QTimerEvent *event)
nodes << node;
}
- for (Node *node : qAsConst(nodes))
+ for (Node *node : std::as_const(nodes))
node->calculateForces();
bool itemsMoved = false;
- for (Node *node : qAsConst(nodes)) {
+ for (Node *node : std::as_const(nodes)) {
if (node->advancePosition())
itemsMoved = true;
}
diff --git a/examples/widgets/graphicsview/elasticnodes/node.cpp b/examples/widgets/graphicsview/elasticnodes/node.cpp
index fd8df0b32b..eb102f0aa4 100644
--- a/examples/widgets/graphicsview/elasticnodes/node.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/node.cpp
@@ -67,7 +67,7 @@ void Node::calculateForces()
//! [4]
// Now subtract all forces pulling items together
double weight = (edgeList.size() + 1) * 10;
- for (const Edge *edge : qAsConst(edgeList)) {
+ for (const Edge *edge : std::as_const(edgeList)) {
QPointF vec;
if (edge->sourceNode() == this)
vec = mapToItem(edge->destNode(), 0, 0);
@@ -148,7 +148,7 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
{
switch (change) {
case ItemPositionHasChanged:
- for (Edge *edge : qAsConst(edgeList))
+ for (Edge *edge : std::as_const(edgeList))
edge->adjust();
graph->itemMoved();
break;
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
index 1f9fb25e75..ab5f4717b3 100644
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
@@ -102,7 +102,7 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const
} else if (constraint.height() >= 0) { // width for height?
// not supported
} else {
- for (const QGraphicsLayoutItem *item : qAsConst(m_items))
+ for (const QGraphicsLayoutItem *item : std::as_const(m_items))
size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize));
size += QSizeF(left + right, top + bottom);
}
@@ -116,7 +116,7 @@ QSizeF FlowLayout::prefSize() const
qreal maxh = 0;
qreal totalWidth = 0;
- for (const QGraphicsLayoutItem *item : qAsConst(m_items)) {
+ for (const QGraphicsLayoutItem *item : std::as_const(m_items)) {
if (totalWidth > 0)
totalWidth += spacing(Qt::Horizontal);
QSizeF pref = item->effectiveSizeHint(Qt::PreferredSize);
@@ -135,7 +135,7 @@ QSizeF FlowLayout::maxSize() const
{
qreal totalWidth = 0;
qreal totalHeight = 0;
- for (const QGraphicsLayoutItem *item : qAsConst(m_items)) {
+ for (const QGraphicsLayoutItem *item : std::as_const(m_items)) {
if (totalWidth > 0)
totalWidth += spacing(Qt::Horizontal);
if (totalHeight > 0)
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.h b/examples/widgets/graphicsview/flowlayout/flowlayout.h
index 43c469ac3c..028394827a 100644
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.h
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.h
@@ -1,6 +1,9 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#ifndef FLOWLAYOUT_H
+#define FLOWLAYOUT_H
+
#include <QGraphicsLayout>
class FlowLayout : public QGraphicsLayout
@@ -37,3 +40,5 @@ inline void FlowLayout::addItem(QGraphicsLayoutItem *item)
{
insertItem(-1, item);
}
+
+#endif // FLOWLAYOUT_H
diff --git a/examples/widgets/graphicsview/flowlayout/window.h b/examples/widgets/graphicsview/flowlayout/window.h
index 54c27929ac..2fc5570406 100644
--- a/examples/widgets/graphicsview/flowlayout/window.h
+++ b/examples/widgets/graphicsview/flowlayout/window.h
@@ -1,6 +1,9 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#ifndef WINDOW_H
+#define WINDOW_H
+
#include <QGraphicsWidget>
class Window : public QGraphicsWidget
@@ -9,3 +12,5 @@ class Window : public QGraphicsWidget
public:
Window(QGraphicsItem *parent = nullptr);
};
+
+#endif // WINDOW_H
diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp
index 955a766750..6be8867a94 100644
--- a/examples/widgets/itemviews/addressbook/addresswidget.cpp
+++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp
@@ -164,7 +164,7 @@ void AddressWidget::readFromFile(const QString &fileName)
QMessageBox::information(this, tr("No contacts in file"),
tr("The file you are attempting to open contains no contacts."));
} else {
- for (const auto &contact: qAsConst(contacts))
+ for (const auto &contact: std::as_const(contacts))
addEntry(contact.name, contact.address);
}
}
diff --git a/examples/widgets/itemviews/editabletreemodel/treeitem.cpp b/examples/widgets/itemviews/editabletreemodel/treeitem.cpp
index 5784202b93..942ba277a3 100644
--- a/examples/widgets/itemviews/editabletreemodel/treeitem.cpp
+++ b/examples/widgets/itemviews/editabletreemodel/treeitem.cpp
@@ -88,7 +88,7 @@ bool TreeItem::insertColumns(int position, int columns)
for (int column = 0; column < columns; ++column)
itemData.insert(position, QVariant());
- for (TreeItem *child : qAsConst(childItems))
+ for (TreeItem *child : std::as_const(childItems))
child->insertColumns(position, columns);
return true;
@@ -123,7 +123,7 @@ bool TreeItem::removeColumns(int position, int columns)
for (int column = 0; column < columns; ++column)
itemData.remove(position);
- for (TreeItem *child : qAsConst(childItems))
+ for (TreeItem *child : std::as_const(childItems))
child->removeColumns(position, columns);
return true;
diff --git a/examples/widgets/layouts/basiclayouts/dialog.cpp b/examples/widgets/layouts/basiclayouts/dialog.cpp
index aeace90822..a0825167d9 100644
--- a/examples/widgets/layouts/basiclayouts/dialog.cpp
+++ b/examples/widgets/layouts/basiclayouts/dialog.cpp
@@ -36,9 +36,24 @@ Dialog::Dialog()
mainLayout->addWidget(formGroupBox);
mainLayout->addWidget(bigEditor);
mainLayout->addWidget(buttonBox);
-//! [4] //! [5]
- setLayout(mainLayout);
+//! [4]
+ QWidget *scrollAreaContent = new QWidget;
+ scrollAreaContent->setLayout(mainLayout);
+ QScrollArea *scrollArea = new QScrollArea;
+ scrollArea->setFrameShape(QFrame::NoFrame);
+ scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ scrollArea->setWidgetResizable(true);
+ scrollArea->verticalScrollBar()->setStyleSheet("QScrollBar:vertical {width: 20px;}");
+
+ scrollArea->setWidget(scrollAreaContent);
+
+ QVBoxLayout *scrollLayout = new QVBoxLayout;
+ scrollLayout->setContentsMargins(0,0,0,0);
+ scrollLayout->addWidget(scrollArea);
+
+//! [5]
+ setLayout(scrollLayout);
setWindowTitle(tr("Basic Layouts"));
}
//! [5]
diff --git a/examples/widgets/layouts/dynamiclayouts/dialog.cpp b/examples/widgets/layouts/dynamiclayouts/dialog.cpp
index 8dc3d069bc..28b4fc2f7f 100644
--- a/examples/widgets/layouts/dynamiclayouts/dialog.cpp
+++ b/examples/widgets/layouts/dynamiclayouts/dialog.cpp
@@ -57,7 +57,7 @@ void Dialog::rotateWidgets()
{
Q_ASSERT(rotatableWidgets.count() % 2 == 0);
- for (QWidget *widget : qAsConst(rotatableWidgets))
+ for (QWidget *widget : std::as_const(rotatableWidgets))
rotatableLayout->removeWidget(widget);
rotatableWidgets.enqueue(rotatableWidgets.dequeue());
diff --git a/examples/widgets/layouts/flowlayout/flowlayout.cpp b/examples/widgets/layouts/flowlayout/flowlayout.cpp
index b4cba9fe69..0565053096 100644
--- a/examples/widgets/layouts/flowlayout/flowlayout.cpp
+++ b/examples/widgets/layouts/flowlayout/flowlayout.cpp
@@ -108,7 +108,7 @@ QSize FlowLayout::sizeHint() const
QSize FlowLayout::minimumSize() const
{
QSize size;
- for (const QLayoutItem *item : qAsConst(itemList))
+ for (const QLayoutItem *item : std::as_const(itemList))
size = size.expandedTo(item->minimumSize());
const QMargins margins = contentsMargins();
@@ -129,7 +129,7 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
//! [9]
//! [10]
- for (QLayoutItem *item : qAsConst(itemList)) {
+ for (QLayoutItem *item : std::as_const(itemList)) {
const QWidget *wid = item->widget();
int spaceX = horizontalSpacing();
if (spaceX == -1)
diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp
index 93ca5259aa..b902498b2d 100644
--- a/examples/widgets/painting/composition/composition.cpp
+++ b/examples/widgets/painting/composition/composition.cpp
@@ -219,6 +219,7 @@ CompositionRenderer::CompositionRenderer(QWidget *parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
#if QT_CONFIG(opengl)
m_pbuffer_size = 1024;
+ m_base_tex = 0;
#endif
}
@@ -314,6 +315,7 @@ void CompositionRenderer::paint(QPainter *painter)
{
#if QT_CONFIG(opengl)
if (usesOpenGL() && glWindow()->isValid()) {
+ auto *funcs = QOpenGLContext::currentContext()->functions();
if (!m_blitter.isCreated())
m_blitter.create();
@@ -338,10 +340,13 @@ void CompositionRenderer::paint(QPainter *painter)
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
drawBase(p);
p.end();
+ if (m_base_tex)
+ funcs->glDeleteTextures(1, &m_base_tex);
m_base_tex = m_fbo->takeTexture();
}
painter->beginNativePainting();
+ uint compositingTex;
{
QPainter p(m_fbo.get());
p.beginNativePainting();
@@ -353,19 +358,18 @@ void CompositionRenderer::paint(QPainter *painter)
p.endNativePainting();
drawSource(p);
p.end();
- m_compositing_tex = m_fbo->takeTexture();
+ compositingTex = m_fbo->texture();
}
painter->endNativePainting();
painter->beginNativePainting();
- auto *funcs = QOpenGLContext::currentContext()->functions();
funcs->glEnable(GL_BLEND);
funcs->glBlendEquation(GL_FUNC_ADD);
funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
m_blitter.bind();
const QRect targetRect(QPoint(0, 0), m_fbo->size());
const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), size()));
- m_blitter.blit(m_compositing_tex, target, QOpenGLTextureBlitter::OriginBottomLeft);
+ m_blitter.blit(compositingTex, target, QOpenGLTextureBlitter::OriginBottomLeft);
m_blitter.release();
painter->endNativePainting();
} else
diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h
index b2fa2c5bb1..0745eb41b9 100644
--- a/examples/widgets/painting/composition/composition.h
+++ b/examples/widgets/painting/composition/composition.h
@@ -148,7 +148,6 @@ private:
std::unique_ptr<QFboPaintDevice> m_fbo;
int m_pbuffer_size; // width==height==size of pbuffer
uint m_base_tex;
- uint m_compositing_tex;
QSize m_previous_size;
QOpenGLTextureBlitter m_blitter;
#endif
diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp
index 1b1b816395..e2bd768f79 100644
--- a/examples/widgets/painting/fontsampler/mainwindow.cpp
+++ b/examples/widgets/painting/fontsampler/mainwindow.cpp
@@ -260,7 +260,7 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer)
bool italic = item->data(0, Qt::UserRole + 1).toBool();
// Calculate the maximum width and total height of the text.
- for (int size : qAsConst(sampleSizes)) {
+ for (int size : std::as_const(sampleSizes)) {
QFont font(family, size, weight, italic);
font.setStyleName(style);
font = QFont(font, painter->device());
@@ -294,7 +294,7 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer)
bool italic = item->data(0, Qt::UserRole + 1).toBool();
// Draw each line of text.
- for (int size : qAsConst(sampleSizes)) {
+ for (int size : std::as_const(sampleSizes)) {
QFont font(family, size, weight, italic);
font.setStyleName(style);
font = QFont(font, painter->device());
diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp
index dcedd250cf..538d851eb8 100644
--- a/examples/widgets/painting/gradients/gradients.cpp
+++ b/examples/widgets/painting/gradients/gradients.cpp
@@ -534,7 +534,7 @@ void GradientRenderer::paint(QPainter *p)
g = QConicalGradient(pts.at(0), angle);
}
- for (const auto &stop : qAsConst(m_stops))
+ for (const auto &stop : std::as_const(m_stops))
g.setColorAt(stop.first, stop.second);
g.setSpread(m_spread);
diff --git a/examples/widgets/painting/painterpaths/window.cpp b/examples/widgets/painting/painterpaths/window.cpp
index 4fc3e8efd9..01b62d6988 100644
--- a/examples/widgets/painting/painterpaths/window.cpp
+++ b/examples/widgets/painting/painterpaths/window.cpp
@@ -156,7 +156,7 @@ Window::Window()
connect(penColorComboBox, &QComboBox::activated,
this, &Window::penColorChanged);
- for (RenderArea *area : qAsConst(renderAreas)) {
+ for (RenderArea *area : std::as_const(renderAreas)) {
connect(penWidthSpinBox, &QSpinBox::valueChanged,
area, &RenderArea::setPenWidth);
connect(rotationAngleSpinBox, &QSpinBox::valueChanged,
@@ -167,7 +167,7 @@ Window::Window()
QGridLayout *topLayout = new QGridLayout;
int i = 0;
- for (RenderArea *area : qAsConst(renderAreas)) {
+ for (RenderArea *area : std::as_const(renderAreas)) {
topLayout->addWidget(area, i / 3, i % 3);
++i;
}
@@ -204,7 +204,7 @@ void Window::fillRuleChanged()
{
Qt::FillRule rule = (Qt::FillRule)currentItemData(fillRuleComboBox).toInt();
- for (RenderArea *area : qAsConst(renderAreas))
+ for (RenderArea *area : std::as_const(renderAreas))
area->setFillRule(rule);
}
//! [19]
@@ -215,7 +215,7 @@ void Window::fillGradientChanged()
QColor color1 = qvariant_cast<QColor>(currentItemData(fillColor1ComboBox));
QColor color2 = qvariant_cast<QColor>(currentItemData(fillColor2ComboBox));
- for (RenderArea *area : qAsConst(renderAreas))
+ for (RenderArea *area : std::as_const(renderAreas))
area->setFillGradient(color1, color2);
}
//! [20]
@@ -225,7 +225,7 @@ void Window::penColorChanged()
{
QColor color = qvariant_cast<QColor>(currentItemData(penColorComboBox));
- for (RenderArea *area : qAsConst(renderAreas))
+ for (RenderArea *area : std::as_const(renderAreas))
area->setPenColor(color);
}
//! [21]
diff --git a/examples/widgets/painting/shared/fbopaintdevice.cpp b/examples/widgets/painting/shared/fbopaintdevice.cpp
index 305f4f2c2c..5875e6574b 100644
--- a/examples/widgets/painting/shared/fbopaintdevice.cpp
+++ b/examples/widgets/painting/shared/fbopaintdevice.cpp
@@ -24,11 +24,13 @@ QFboPaintDevice::QFboPaintDevice(const QSize &size, bool flipped, bool clearOnIn
context()->functions()->glClearColor(0, 0, 0, 0);
context()->functions()->glClear(GL_COLOR_BUFFER_BIT);
}
+ m_resolvedFbo = new QOpenGLFramebufferObject(m_framebufferObject->size(), m_framebufferObject->attachment());
}
QFboPaintDevice::~QFboPaintDevice()
{
delete m_framebufferObject;
+ delete m_resolvedFbo;
delete m_surface;
}
@@ -40,12 +42,19 @@ void QFboPaintDevice::ensureActiveTarget()
m_framebufferObject->bind();
}
+GLuint QFboPaintDevice::texture()
+{
+ m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
+ QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
+ return m_resolvedFbo->texture();
+}
+
GLuint QFboPaintDevice::takeTexture()
{
- // We have multisamples so we can't just forward takeTexture().
- QOpenGLFramebufferObject resolvedFbo(m_framebufferObject->size(), m_framebufferObject->attachment());
- QOpenGLFramebufferObject::blitFramebuffer(&resolvedFbo, m_framebufferObject);
- return resolvedFbo.takeTexture();
+ m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
+ // We have multisamples so we can't just forward takeTexture(), have to resolve first.
+ QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
+ return m_resolvedFbo->takeTexture();
}
QImage QFboPaintDevice::toImage() const
diff --git a/examples/widgets/painting/shared/fbopaintdevice.h b/examples/widgets/painting/shared/fbopaintdevice.h
index a46166217b..b2e77a228a 100644
--- a/examples/widgets/painting/shared/fbopaintdevice.h
+++ b/examples/widgets/painting/shared/fbopaintdevice.h
@@ -22,6 +22,7 @@ public:
bool isValid() const { return m_framebufferObject->isValid(); }
GLuint handle() const { return m_framebufferObject->handle(); }
+ GLuint texture();
GLuint takeTexture();
QImage toImage() const;
@@ -36,6 +37,7 @@ public:
private:
QOpenGLFramebufferObject *m_framebufferObject;
+ QOpenGLFramebufferObject *m_resolvedFbo;
QSurface *m_surface;
};
diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp
index 7d2bb81538..87e1eb4415 100644
--- a/examples/widgets/painting/shared/hoverpoints.cpp
+++ b/examples/widgets/painting/shared/hoverpoints.cpp
@@ -268,7 +268,7 @@ void HoverPoints::paintPoints()
p.setPen(m_pointPen);
p.setBrush(m_pointBrush);
- for (const auto &point : qAsConst(m_points)) {
+ for (const auto &point : std::as_const(m_points)) {
QRectF bounds = pointBoundingRect(point);
if (m_shape == CircleShape)
p.drawEllipse(bounds);
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
index 11e203c333..d78de20a7d 100644
--- a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
@@ -72,7 +72,7 @@ Highlighter::Highlighter(QTextDocument *parent)
//! [7]
void Highlighter::highlightBlock(const QString &text)
{
- for (const HighlightingRule &rule : qAsConst(highlightingRules)) {
+ for (const HighlightingRule &rule : std::as_const(highlightingRules)) {
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
while (matchIterator.hasNext()) {
QRegularExpressionMatch match = matchIterator.next();
diff --git a/examples/widgets/tutorials/modelview/1_readonly/mymodel.h b/examples/widgets/tutorials/modelview/1_readonly/mymodel.h
index ec2833fa08..ab26790a03 100644
--- a/examples/widgets/tutorials/modelview/1_readonly/mymodel.h
+++ b/examples/widgets/tutorials/modelview/1_readonly/mymodel.h
@@ -12,7 +12,8 @@ class MyModel : public QAbstractTableModel
{
Q_OBJECT
public:
- MyModel(QObject *parent = nullptr);
+ explicit MyModel(QObject *parent = nullptr);
+
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
diff --git a/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp b/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp
index 0203345540..229aa48ad7 100644
--- a/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp
+++ b/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp
@@ -41,22 +41,22 @@ QVariant MyModel::data(const QModelIndex &index, int role) const
.arg(row + 1)
.arg(col +1);
case Qt::FontRole:
- if (row == 0 && col == 0) { //change font only for cell(0,0)
+ if (row == 0 && col == 0) { // change font only for cell(0,0)
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
break;
case Qt::BackgroundRole:
- if (row == 1 && col == 2) //change background only for cell(1,2)
+ if (row == 1 && col == 2) // change background only for cell(1,2)
return QBrush(Qt::red);
break;
case Qt::TextAlignmentRole:
- if (row == 1 && col == 1) //change text alignment only for cell(1,1)
+ if (row == 1 && col == 1) // change text alignment only for cell(1,1)
return int(Qt::AlignRight | Qt::AlignVCenter);
break;
case Qt::CheckStateRole:
- if (row == 1 && col == 0) //add a checkbox to cell(1,0)
+ if (row == 1 && col == 0) // add a checkbox to cell(1,0)
return Qt::Checked;
break;
}
diff --git a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h
index 300b1ede0b..bd3d0afe17 100644
--- a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h
+++ b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h
@@ -10,7 +10,8 @@ class MyModel : public QAbstractTableModel
{
Q_OBJECT
public:
- MyModel(QObject *parent = nullptr);
+ explicit MyModel(QObject *parent = nullptr);
+
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp
index 82ba17dc45..5ce56632ff 100644
--- a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp
+++ b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp
@@ -44,9 +44,9 @@ QVariant MyModel::data(const QModelIndex &index, int role) const
//! [quoting mymodel_b ]
void MyModel::timerHit()
{
- //we identify the top left cell
+ // we identify the top left cell
QModelIndex topLeft = createIndex(0,0);
- //emit a signal to make the view reread identified data
+ // emit a signal to make the view reread identified data
emit dataChanged(topLeft, topLeft, {Qt::DisplayRole});
}
//! [quoting mymodel_b ]
diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h
index 70a32f10be..5fab806c42 100644
--- a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h
+++ b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h
@@ -11,14 +11,17 @@ class MyModel : public QAbstractTableModel
{
Q_OBJECT
public:
- MyModel(QObject *parent = nullptr);
+ explicit MyModel(QObject *parent = nullptr);
+
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
-private:
- QTimer *timer;
+
private slots:
void timerHit();
+
+private:
+ QTimer *timer;
};
#endif // MYMODEL_H
diff --git a/examples/widgets/tutorials/modelview/4_headers/mymodel.h b/examples/widgets/tutorials/modelview/4_headers/mymodel.h
index 4bf0b4837e..43e708c297 100644
--- a/examples/widgets/tutorials/modelview/4_headers/mymodel.h
+++ b/examples/widgets/tutorials/modelview/4_headers/mymodel.h
@@ -10,7 +10,8 @@ class MyModel : public QAbstractTableModel
{
Q_OBJECT
public:
- MyModel(QObject *parent = nullptr);
+ explicit MyModel(QObject *parent = nullptr);
+
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
diff --git a/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp b/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp
index 863dcc5080..4fe164e888 100644
--- a/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp
+++ b/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp
@@ -11,15 +11,10 @@ MainWindow::MainWindow(QWidget *parent)
, tableView(new QTableView(this))
{
setCentralWidget(tableView);
- MyModel *myModel = new MyModel(this);
+ auto *myModel = new MyModel(this);
tableView->setModel(myModel);
- //transfer changes to the model to the window title
+ // transfer changes to the model to the window title
connect(myModel, &MyModel::editCompleted,
- this, &MainWindow::showWindowTitle);
-}
-
-void MainWindow::showWindowTitle(const QString &title)
-{
- setWindowTitle(title);
+ this, &QWidget::setWindowTitle);
}
diff --git a/examples/widgets/tutorials/modelview/5_edit/mainwindow.h b/examples/widgets/tutorials/modelview/5_edit/mainwindow.h
index e8ef3cccea..2ec6fce57d 100644
--- a/examples/widgets/tutorials/modelview/5_edit/mainwindow.h
+++ b/examples/widgets/tutorials/modelview/5_edit/mainwindow.h
@@ -7,19 +7,18 @@
#include <QMainWindow>
QT_BEGIN_NAMESPACE
-class QTableView; //forward declaration
+class QTableView; // forward declaration
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
+public:
+ explicit MainWindow(QWidget *parent = nullptr);
+
private:
QTableView *tableView;
-public:
- MainWindow(QWidget *parent = nullptr);
-public slots:
- void showWindowTitle(const QString &title);
};
#endif // MAINWINDOW_H
diff --git a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h
index b533c0283e..38446c7a73 100644
--- a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h
+++ b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h
@@ -7,7 +7,7 @@
#include <QMainWindow>
QT_BEGIN_NAMESPACE
-class QTreeView; //forward declarations
+class QTreeView; // forward declarations
class QStandardItemModel;
class QStandardItem;
QT_END_NAMESPACE
@@ -16,14 +16,16 @@ QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
+public:
+ explicit MainWindow(QWidget *parent = nullptr);
+
private:
- QTreeView *treeView;
- QStandardItemModel *standardModel;
QList<QStandardItem *> prepareRow(const QString &first,
const QString &second,
const QString &third) const;
-public:
- MainWindow(QWidget *parent = nullptr);
+
+ QTreeView *treeView;
+ QStandardItemModel *standardModel;
};
#endif // MAINWINDOW_H
diff --git a/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp b/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp
index 0539d49ce6..3bedb2f82c 100644
--- a/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp
+++ b/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp
@@ -14,20 +14,20 @@ MainWindow::MainWindow(QWidget *parent)
, standardModel(new QStandardItemModel(this))
{
setCentralWidget(treeView);
- QStandardItem *rootNode = standardModel->invisibleRootItem();
+ auto *rootNode = standardModel->invisibleRootItem();
- //defining a couple of items
- QStandardItem *americaItem = new QStandardItem("America");
- QStandardItem *mexicoItem = new QStandardItem("Canada");
- QStandardItem *usaItem = new QStandardItem("USA");
- QStandardItem *bostonItem = new QStandardItem("Boston");
- QStandardItem *europeItem = new QStandardItem("Europe");
- QStandardItem *italyItem = new QStandardItem("Italy");
- QStandardItem *romeItem = new QStandardItem("Rome");
- QStandardItem *veronaItem = new QStandardItem("Verona");
+ // defining a couple of items
+ auto *americaItem = new QStandardItem("America");
+ auto *mexicoItem = new QStandardItem("Canada");
+ auto *usaItem = new QStandardItem("USA");
+ auto *bostonItem = new QStandardItem("Boston");
+ auto *europeItem = new QStandardItem("Europe");
+ auto *italyItem = new QStandardItem("Italy");
+ auto *romeItem = new QStandardItem("Rome");
+ auto *veronaItem = new QStandardItem("Verona");
- //building up the hierarchy
+ // building up the hierarchy
rootNode-> appendRow(americaItem);
rootNode-> appendRow(europeItem);
americaItem-> appendRow(mexicoItem);
@@ -37,11 +37,11 @@ MainWindow::MainWindow(QWidget *parent)
italyItem-> appendRow(romeItem);
italyItem-> appendRow(veronaItem);
- //register the model
+ // register the model
treeView->setModel(standardModel);
treeView->expandAll();
- //selection changes shall trigger a slot
+ // selection changes shall trigger a slot
QItemSelectionModel *selectionModel = treeView->selectionModel();
connect(selectionModel, &QItemSelectionModel::selectionChanged,
this, &MainWindow::selectionChangedSlot);
@@ -53,13 +53,13 @@ MainWindow::MainWindow(QWidget *parent)
//! [quoting modelview_b]
void MainWindow::selectionChangedSlot(const QItemSelection & /*newSelection*/, const QItemSelection & /*oldSelection*/)
{
- //get the text of the selected item
+ // get the text of the selected item
const QModelIndex index = treeView->selectionModel()->currentIndex();
QString selectedText = index.data(Qt::DisplayRole).toString();
- //find out the hierarchy level of the selected item
+ // find out the hierarchy level of the selected item
int hierarchyLevel = 1;
QModelIndex seekRoot = index;
- while (seekRoot.parent() != QModelIndex()) {
+ while (seekRoot.parent().isValid()) {
seekRoot = seekRoot.parent();
hierarchyLevel++;
}
diff --git a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h
index a0d05222fa..cca1ae837f 100644
--- a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h
+++ b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h
@@ -7,7 +7,7 @@
#include <QMainWindow>
QT_BEGIN_NAMESPACE
-class QTreeView; //forward declarations
+class QTreeView; // forward declarations
class QStandardItemModel;
class QItemSelection;
QT_END_NAMESPACE
@@ -16,13 +16,15 @@ QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
+public:
+ explicit MainWindow(QWidget *parent = nullptr);
+
+private slots:
+ void selectionChangedSlot(const QItemSelection &newSelection, const QItemSelection &oldSelection);
+
private:
QTreeView *treeView;
QStandardItemModel *standardModel;
-private slots:
- void selectionChangedSlot(const QItemSelection &newSelection, const QItemSelection &oldSelection);
-public:
- MainWindow(QWidget *parent = nullptr);
};
#endif // MAINWINDOW_H
diff --git a/examples/widgets/widgets/scribble/mainwindow.cpp b/examples/widgets/widgets/scribble/mainwindow.cpp
index b7e08598f7..0a0a658265 100644
--- a/examples/widgets/widgets/scribble/mainwindow.cpp
+++ b/examples/widgets/widgets/scribble/mainwindow.cpp
@@ -153,7 +153,7 @@ void MainWindow::createMenus()
//! [15] //! [16]
{
saveAsMenu = new QMenu(tr("&Save As"), this);
- for (QAction *action : qAsConst(saveAsActs))
+ for (QAction *action : std::as_const(saveAsActs))
saveAsMenu->addAction(action);
fileMenu = new QMenu(tr("&File"), this);
diff --git a/examples/widgets/widgets/sliders/window.cpp b/examples/widgets/widgets/sliders/window.cpp
index 397c9b8b72..4a3520716d 100644
--- a/examples/widgets/widgets/sliders/window.cpp
+++ b/examples/widgets/widgets/sliders/window.cpp
@@ -3,10 +3,8 @@
#include "slidersgroup.h"
#include "window.h"
-
#include <QCheckBox>
#include <QComboBox>
-#include <QHBoxLayout>
#include <QLabel>
#include <QSpinBox>
#include <QStackedWidget>
@@ -34,9 +32,10 @@ Window::Window(QWidget *parent)
connect(valueSpinBox, &QSpinBox::valueChanged,
horizontalSliders, &SlidersGroup::setValue);
- QHBoxLayout *layout = new QHBoxLayout;
- layout->addWidget(controlsGroup);
- layout->addWidget(stackedWidget);
+ layout = new QGridLayout;
+ layout->addWidget(stackedWidget, 0, 1);
+ layout->addWidget(controlsGroup, 0, 0);
+
setLayout(layout);
minimumSpinBox->setValue(0);
@@ -110,5 +109,37 @@ void Window::createControls(const QString &title)
controlsLayout->addWidget(invertedKeyBindings, 1, 2);
controlsLayout->addWidget(orientationCombo, 3, 0, 1, 3);
controlsGroup->setLayout(controlsLayout);
+
}
//! [8]
+
+
+void Window::resizeEvent(QResizeEvent *e)
+{
+ if (width() == 0 || height() == 0)
+ return;
+
+ const double aspectRatio = double(width()) / double(height());
+
+ if ((aspectRatio < 1.0) && (oldAspectRatio > 1.0)) {
+ layout->removeWidget(controlsGroup);
+ layout->removeWidget(stackedWidget);
+
+ layout->addWidget(stackedWidget, 1, 0);
+ layout->addWidget(controlsGroup, 0, 0);
+
+ oldAspectRatio = aspectRatio;
+ }
+ else if ((aspectRatio > 1.0) && (oldAspectRatio < 1.0)) {
+ layout->removeWidget(controlsGroup);
+ layout->removeWidget(stackedWidget);
+
+ layout->addWidget(stackedWidget, 0, 1);
+ layout->addWidget(controlsGroup, 0, 0);
+
+ oldAspectRatio = aspectRatio;
+ }
+}
+
+
+
diff --git a/examples/widgets/widgets/sliders/window.h b/examples/widgets/widgets/sliders/window.h
index 8a98fcb2a1..fa627eabd3 100644
--- a/examples/widgets/widgets/sliders/window.h
+++ b/examples/widgets/widgets/sliders/window.h
@@ -5,6 +5,7 @@
#define WINDOW_H
#include <QWidget>
+#include <QGridLayout>
QT_BEGIN_NAMESPACE
class QCheckBox;
@@ -26,6 +27,7 @@ public:
private:
void createControls(const QString &title);
+ void resizeEvent(QResizeEvent *e);
SlidersGroup *horizontalSliders;
SlidersGroup *verticalSliders;
@@ -41,6 +43,8 @@ private:
QSpinBox *maximumSpinBox;
QSpinBox *valueSpinBox;
QComboBox *orientationCombo;
+ QGridLayout *layout;
+ double oldAspectRatio;
};
//! [0]
diff --git a/examples/widgets/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp
index 2b9127f5bd..1f6de0bd8c 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.cpp
+++ b/examples/widgets/widgets/tooltips/sortingbox.cpp
@@ -97,7 +97,7 @@ void SortingBox::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
- for (const ShapeItem &shapeItem : qAsConst(shapeItems)) {
+ for (const ShapeItem &shapeItem : std::as_const(shapeItems)) {
//! [8] //! [9]
painter.translate(shapeItem.position());
//! [9] //! [10]
diff --git a/examples/widgets/widgets/validators/validatorwidget.h b/examples/widgets/widgets/validators/validatorwidget.h
index 635257f16b..d186c5863b 100644
--- a/examples/widgets/widgets/validators/validatorwidget.h
+++ b/examples/widgets/widgets/validators/validatorwidget.h
@@ -1,6 +1,9 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#ifndef VALIDATORWIDGET_H
+#define VALIDATORWIDGET_H
+
#include <QWidget>
#include "ui_validators.h"
@@ -15,3 +18,5 @@ private slots:
void updateValidator();
void updateDoubleValidator();
};
+
+#endif // VALIDATORWIDGET_H