summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/desktop/desktop.pro1
-rw-r--r--examples/widgets/doc/src/stylesheet.qdoc2
-rw-r--r--examples/widgets/doc/src/wiggly.qdoc8
-rw-r--r--examples/widgets/effects/fademessage/fademessage.cpp2
-rw-r--r--examples/widgets/itemviews/fetchmore/filelistmodel.cpp3
-rw-r--r--examples/widgets/itemviews/flattreeview/flattreeview.pro7
-rw-r--r--examples/widgets/itemviews/flattreeview/main.cpp84
-rw-r--r--examples/widgets/itemviews/itemviews.pro1
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.cpp10
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp2
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.cpp2
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.h4
-rw-r--r--examples/widgets/mainwindows/mainwindow/main.cpp2
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.cpp2
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.h2
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.cpp37
-rw-r--r--examples/widgets/mainwindows/sdi/main.cpp2
-rw-r--r--examples/widgets/painting/deform/pathdeform.cpp2
-rw-r--r--examples/widgets/painting/shared/arthurstyle.cpp4
-rw-r--r--examples/widgets/statemachine/rogue/window.cpp4
-rw-r--r--examples/widgets/tools/codecs/previewform.h2
-rw-r--r--examples/widgets/tools/completer/fsmodel.h2
-rw-r--r--examples/widgets/tools/settingseditor/mainwindow.cpp2
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.cpp2
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.cpp2
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.cpp2
-rw-r--r--examples/widgets/widgets/icons/iconpreviewarea.cpp2
-rw-r--r--examples/widgets/widgets/icons/iconpreviewarea.h2
-rw-r--r--examples/widgets/widgets/icons/iconsizespinbox.h2
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.h2
-rw-r--r--examples/widgets/widgets/tablet/mainwindow.cpp2
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.cpp9
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.h2
-rw-r--r--examples/widgets/widgets/wiggly/wigglywidget.cpp4
34 files changed, 162 insertions, 56 deletions
diff --git a/examples/widgets/desktop/desktop.pro b/examples/widgets/desktop/desktop.pro
index db518c1c7a..4c9d0e2cec 100644
--- a/examples/widgets/desktop/desktop.pro
+++ b/examples/widgets/desktop/desktop.pro
@@ -1,3 +1,2 @@
TEMPLATE = subdirs
-CONFIG += ordered
SUBDIRS = screenshot systray
diff --git a/examples/widgets/doc/src/stylesheet.qdoc b/examples/widgets/doc/src/stylesheet.qdoc
index a86b697059..26c5663022 100644
--- a/examples/widgets/doc/src/stylesheet.qdoc
+++ b/examples/widgets/doc/src/stylesheet.qdoc
@@ -48,7 +48,7 @@
\section1 MainWindow Class
\c MainWindow inherits QWidget, and is the application's main window defined in
- \c mainwindow.ui. The style of \c MainWindow can be modified with \l StyleSheetEditor.
+ \c mainwindow.ui. The style of \c MainWindow can be modified with \c StyleSheetEditor.
\section1 StyleSheetEditor Class
diff --git a/examples/widgets/doc/src/wiggly.qdoc b/examples/widgets/doc/src/wiggly.qdoc
index f330b016df..d70d609e2b 100644
--- a/examples/widgets/doc/src/wiggly.qdoc
+++ b/examples/widgets/doc/src/wiggly.qdoc
@@ -143,10 +143,10 @@
position on the wiggly line based on \c step. In addition, \c x
is incremented by the character's width.
- For simplicity, we assume that QFontMetrics::width(\c text)
- returns the sum of the individual character widths
- (QFontMetrics::width(\c text[i])). In practice, this is not
- always the case because QFontMetrics::width(\c text) also takes
+ For simplicity, we assume that QFontMetrics::horizontalAdvance(\c text)
+ returns the sum of the individual character advances
+ (QFontMetrics::horizontalAdvance(\c text[i])). In practice, this is not
+ always the case because QFontMetrics::horizontalAdvance(\c text) also takes
into account the kerning between certain letters (e.g., 'A' and
'V'). The result is that the text isn't perfectly centered. You
can verify this by typing "AVAVAVAVAVAV" in the line edit.
diff --git a/examples/widgets/effects/fademessage/fademessage.cpp b/examples/widgets/effects/fademessage/fademessage.cpp
index d91293288c..9943147bb7 100644
--- a/examples/widgets/effects/fademessage/fademessage.cpp
+++ b/examples/widgets/effects/fademessage/fademessage.cpp
@@ -108,7 +108,7 @@ void FadeMessage::setupScene()
int fh = fontMetrics.height();
QString sceneText = "Qt Everywhere!";
- int sceneTextWidth = fontMetrics.width(sceneText);
+ int sceneTextWidth = fontMetrics.horizontalAdvance(sceneText);
QGraphicsRectItem *block = m_scene.addRect(50, 300, sceneTextWidth, fh + 3);
block->setPen(Qt::NoPen);
diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
index cd21712e04..086d45eca3 100644
--- a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
+++ b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
@@ -103,6 +103,9 @@ void FileListModel::fetchMore(const QModelIndex & /* index */)
int remainder = fileList.size() - fileCount;
int itemsToFetch = qMin(100, remainder);
+ if (itemsToFetch <= 0)
+ return;
+
beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch-1);
fileCount += itemsToFetch;
diff --git a/examples/widgets/itemviews/flattreeview/flattreeview.pro b/examples/widgets/itemviews/flattreeview/flattreeview.pro
new file mode 100644
index 0000000000..05a6573d33
--- /dev/null
+++ b/examples/widgets/itemviews/flattreeview/flattreeview.pro
@@ -0,0 +1,7 @@
+QT += widgets
+
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/flattreeview
+INSTALLS += target
diff --git a/examples/widgets/itemviews/flattreeview/main.cpp b/examples/widgets/itemviews/flattreeview/main.cpp
new file mode 100644
index 0000000000..e9bbb3fab1
--- /dev/null
+++ b/examples/widgets/itemviews/flattreeview/main.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
+** 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$
+**
+****************************************************************************/
+
+/*
+ main.cpp
+
+ A simple example that shows a multi-column list using QTreeView.
+ The data is not a tree, so the first column was made movable.
+*/
+
+#include <QApplication>
+#include <QHeaderView>
+#include <QStandardItemModel>
+#include <QTreeView>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QStandardItemModel model(4, 2);
+ QTreeView treeView;
+ treeView.setModel(&model);
+ treeView.setRootIsDecorated(false);
+ treeView.header()->setFirstSectionMovable(true);
+ treeView.header()->setStretchLastSection(true);
+
+ for (int row = 0; row < 4; ++row) {
+ for (int column = 0; column < 2; ++column) {
+ QModelIndex index = model.index(row, column, QModelIndex());
+ model.setData(index, QVariant((row + 1) * (column + 1)));
+ }
+ }
+
+ treeView.setWindowTitle(QObject::tr("Flat Tree View"));
+ treeView.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/itemviews.pro b/examples/widgets/itemviews/itemviews.pro
index 787217a8e8..75307bd74e 100644
--- a/examples/widgets/itemviews/itemviews.pro
+++ b/examples/widgets/itemviews/itemviews.pro
@@ -8,6 +8,7 @@ SUBDIRS = addressbook \
dirview \
editabletreemodel \
fetchmore \
+ flattreeview \
frozencolumn \
interview \
pixelator \
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.cpp b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
index f0649d3776..28b46836f4 100644
--- a/examples/widgets/itemviews/puzzle/piecesmodel.cpp
+++ b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
@@ -203,10 +203,12 @@ Qt::DropActions PiecesModel::supportedDropActions() const
void PiecesModel::addPieces(const QPixmap& pixmap)
{
- beginRemoveRows(QModelIndex(), 0, 24);
- pixmaps.clear();
- locations.clear();
- endRemoveRows();
+ if (!pixmaps.isEmpty()) {
+ beginRemoveRows(QModelIndex(), 0, pixmaps.size() - 1);
+ pixmaps.clear();
+ locations.clear();
+ endRemoveRows();
+ }
for (int y = 0; y < 5; ++y) {
for (int x = 0; x < 5; ++x) {
QPixmap pieceImage = pixmap.copy(x*m_PieceSize, y*m_PieceSize, m_PieceSize, m_PieceSize);
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp
index e9d5235ddc..4c18fa8251 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp
@@ -117,7 +117,7 @@ QVariant SpreadSheetItem::computeFormula(const QString &formula,
const QTableWidget *widget,
const QTableWidgetItem *self)
{
- // check if the s tring is actually a formula or not
+ // check if the string is actually a formula or not
QStringList list = formula.split(' ');
if (list.isEmpty() || !widget)
return formula; // it is a normal string
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
index c47b80275f..720f9a2085 100644
--- a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
+++ b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
@@ -468,7 +468,7 @@ static ColorSwatch *findByName(const QMainWindow *mainWindow, const QString &nam
if (name == dock->objectName())
return dock;
}
- return Q_NULLPTR;
+ return nullptr;
}
void ColorSwatch::splitInto(QAction *action)
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.h b/examples/widgets/mainwindows/mainwindow/colorswatch.h
index ec9d9e7372..7f73e46f31 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 = Q_NULLPTR, Qt::WindowFlags flags = 0);
+ explicit ColorSwatch(const QString &colorName, QMainWindow *parent = nullptr, Qt::WindowFlags flags = 0);
void setCustomSizeHint(const QSize &size);
QMenu *colorSwatchMenu() const { return menu; }
@@ -128,7 +128,7 @@ class BlueTitleBar : public QWidget
{
Q_OBJECT
public:
- explicit BlueTitleBar(QWidget *parent = Q_NULLPTR);
+ explicit BlueTitleBar(QWidget *parent = nullptr);
QSize sizeHint() const override { return minimumSizeHint(); }
QSize minimumSizeHint() const override;
diff --git a/examples/widgets/mainwindows/mainwindow/main.cpp b/examples/widgets/mainwindows/mainwindow/main.cpp
index c78022e392..b82f67b361 100644
--- a/examples/widgets/mainwindows/mainwindow/main.cpp
+++ b/examples/widgets/mainwindows/mainwindow/main.cpp
@@ -175,6 +175,8 @@ static ParseCommandLineArgumentsResult
int main(int argc, char **argv)
{
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication app(argc, argv);
MainWindow::CustomSizeHintMap customSizeHints;
switch (parseCustomSizeHints(QCoreApplication::arguments(), &customSizeHints)) {
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
index afceddfca1..b2c5ccc473 100644
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
@@ -382,7 +382,7 @@ void MainWindow::switchLayoutDirection()
class CreateDockWidgetDialog : public QDialog
{
public:
- explicit CreateDockWidgetDialog(QWidget *parent = Q_NULLPTR);
+ explicit CreateDockWidgetDialog(QWidget *parent = nullptr);
QString enteredObjectName() const { return m_objectName->text(); }
Qt::DockWidgetArea location() const;
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.h b/examples/widgets/mainwindows/mainwindow/mainwindow.h
index af4f1f5745..9b1af6df80 100644
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.h
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.h
@@ -64,7 +64,7 @@ public:
typedef QMap<QString, QSize> CustomSizeHintMap;
explicit MainWindow(const CustomSizeHintMap &customSizeHints,
- QWidget *parent = Q_NULLPTR,
+ QWidget *parent = nullptr,
Qt::WindowFlags flags = 0);
public slots:
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
index 814cfc7f4d..7c96f5b1be 100644
--- a/examples/widgets/mainwindows/mainwindow/toolbar.cpp
+++ b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
@@ -62,10 +62,10 @@
#include <stdlib.h>
-static QPixmap genIcon(const QSize &iconSize, const QString &, const QColor &color)
+static QPixmap genIcon(const QSize &iconSize, const QString &, const QColor &color, qreal pixelRatio)
{
- int w = iconSize.width();
- int h = iconSize.height();
+ int w = qRound(iconSize.width() * pixelRatio);
+ int h = qRound(iconSize.height() * pixelRatio);
QImage image(w, h, QImage::Format_ARGB32_Premultiplied);
image.fill(0);
@@ -75,38 +75,41 @@ static QPixmap genIcon(const QSize &iconSize, const QString &, const QColor &col
extern void render_qt_text(QPainter *, int, int, const QColor &);
render_qt_text(&p, w, h, color);
- return QPixmap::fromImage(image, Qt::DiffuseDither | Qt::DiffuseAlphaDither);
+ QPixmap pm = QPixmap::fromImage(image, Qt::DiffuseDither | Qt::DiffuseAlphaDither);
+ pm.setDevicePixelRatio(pixelRatio);
+ return pm;
}
-static QPixmap genIcon(const QSize &iconSize, int number, const QColor &color)
-{ return genIcon(iconSize, QString::number(number), color); }
+static QPixmap genIcon(const QSize &iconSize, int number, const QColor &color, qreal pixelRatio)
+{ return genIcon(iconSize, QString::number(number), color, pixelRatio); }
ToolBar::ToolBar(const QString &title, QWidget *parent)
: QToolBar(parent)
- , spinbox(Q_NULLPTR)
- , spinboxAction(Q_NULLPTR)
+ , spinbox(nullptr)
+ , spinboxAction(nullptr)
{
setWindowTitle(title);
setObjectName(title);
setIconSize(QSize(32, 32));
+ qreal dpr = devicePixelRatioF();
menu = new QMenu("One", this);
- menu->setIcon(genIcon(iconSize(), 1, Qt::black));
- menu->addAction(genIcon(iconSize(), "A", Qt::blue), "A");
- menu->addAction(genIcon(iconSize(), "B", Qt::blue), "B");
- menu->addAction(genIcon(iconSize(), "C", Qt::blue), "C");
+ menu->setIcon(genIcon(iconSize(), 1, Qt::black, dpr));
+ menu->addAction(genIcon(iconSize(), "A", Qt::blue, dpr), "A");
+ menu->addAction(genIcon(iconSize(), "B", Qt::blue, dpr), "B");
+ menu->addAction(genIcon(iconSize(), "C", Qt::blue, dpr), "C");
addAction(menu->menuAction());
- QAction *two = addAction(genIcon(iconSize(), 2, Qt::white), "Two");
+ QAction *two = addAction(genIcon(iconSize(), 2, Qt::white, dpr), "Two");
QFont boldFont;
boldFont.setBold(true);
two->setFont(boldFont);
- addAction(genIcon(iconSize(), 3, Qt::red), "Three");
- addAction(genIcon(iconSize(), 4, Qt::green), "Four");
- addAction(genIcon(iconSize(), 5, Qt::blue), "Five");
- addAction(genIcon(iconSize(), 6, Qt::yellow), "Six");
+ addAction(genIcon(iconSize(), 3, Qt::red, dpr), "Three");
+ addAction(genIcon(iconSize(), 4, Qt::green, dpr), "Four");
+ addAction(genIcon(iconSize(), 5, Qt::blue, dpr), "Five");
+ addAction(genIcon(iconSize(), 6, Qt::yellow, dpr), "Six");
orderAction = new QAction(this);
orderAction->setText(tr("Order Items in Tool Bar"));
connect(orderAction, &QAction::triggered, this, &ToolBar::order);
diff --git a/examples/widgets/mainwindows/sdi/main.cpp b/examples/widgets/mainwindows/sdi/main.cpp
index bed990d34d..6e29fafd6f 100644
--- a/examples/widgets/mainwindows/sdi/main.cpp
+++ b/examples/widgets/mainwindows/sdi/main.cpp
@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
parser.addPositionalArgument("file", "The file(s) to open.");
parser.process(app);
- MainWindow *mainWin = Q_NULLPTR;
+ MainWindow *mainWin = nullptr;
foreach (const QString &file, parser.positionalArguments()) {
MainWindow *newWin = new MainWindow(file);
newWin->tile(mainWin);
diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp
index 3f72a33902..490a8508d6 100644
--- a/examples/widgets/painting/deform/pathdeform.cpp
+++ b/examples/widgets/painting/deform/pathdeform.cpp
@@ -364,7 +364,7 @@ void PathDeformRenderer::setText(const QString &text)
path.addText(advance, f, text.mid(i, 1));
m_pathBounds |= path.boundingRect();
m_paths << path;
- advance += QPointF(fm.width(text.mid(i, 1)), 0);
+ advance += QPointF(fm.horizontalAdvance(text.mid(i, 1)), 0);
}
} else {
QPainterPath path;
diff --git a/examples/widgets/painting/shared/arthurstyle.cpp b/examples/widgets/painting/shared/arthurstyle.cpp
index 484eaec31c..f4fc76bda6 100644
--- a/examples/widgets/painting/shared/arthurstyle.cpp
+++ b/examples/widgets/painting/shared/arthurstyle.cpp
@@ -294,7 +294,7 @@ void ArthurStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
QPixmap titleLeft = cached(":res/images/title_cap_left.png");
QPixmap titleRight = cached(":res/images/title_cap_right.png");
QPixmap titleStretch = cached(":res/images/title_stretch.png");
- int txt_width = groupBox->fontMetrics.width(groupBox->text) + 20;
+ int txt_width = groupBox->fontMetrics.horizontalAdvance(groupBox->text) + 20;
painter->drawPixmap(r.center().x() - txt_width/2, 0, titleLeft);
QRect tileRect = subControlRect(control, groupBox, SC_GroupBoxLabel, widget);
painter->drawTiledPixmap(tileRect, titleStretch);
@@ -385,7 +385,7 @@ QRect ArthurStyle::subControlRect(ComplexControl control, const QStyleOptionComp
QPixmap titleLeft = cached(":res/images/title_cap_left.png");
QPixmap titleRight = cached(":res/images/title_cap_right.png");
QPixmap titleStretch = cached(":res/images/title_stretch.png");
- int txt_width = group->fontMetrics.width(group->text) + 20;
+ int txt_width = group->fontMetrics.horizontalAdvance(group->text) + 20;
rect = QRect(group->rect.center().x() - txt_width/2 + titleLeft.width(), 0,
txt_width - titleLeft.width() - titleRight.width(),
titleStretch.height());
diff --git a/examples/widgets/statemachine/rogue/window.cpp b/examples/widgets/statemachine/rogue/window.cpp
index 3515138382..059fbf1003 100644
--- a/examples/widgets/statemachine/rogue/window.cpp
+++ b/examples/widgets/statemachine/rogue/window.cpp
@@ -98,7 +98,7 @@ void Window::paintEvent(QPaintEvent * /* event */)
QFontMetrics metrics(font());
QPainter painter(this);
int fontHeight = metrics.height();
- int fontWidth = metrics.width('X');
+ int fontWidth = metrics.horizontalAdvance('X');
int yPos = fontHeight;
int xPos;
@@ -177,7 +177,7 @@ QSize Window::sizeHint() const
{
QFontMetrics metrics(font());
- return QSize(metrics.width('X') * WIDTH, metrics.height() * (HEIGHT + 1));
+ return QSize(metrics.horizontalAdvance('X') * WIDTH, metrics.height() * (HEIGHT + 1));
}
//![2]
diff --git a/examples/widgets/tools/codecs/previewform.h b/examples/widgets/tools/codecs/previewform.h
index 1846b976de..6335b6539f 100644
--- a/examples/widgets/tools/codecs/previewform.h
+++ b/examples/widgets/tools/codecs/previewform.h
@@ -69,7 +69,7 @@ class PreviewForm : public QDialog
Q_OBJECT
public:
- explicit PreviewForm(QWidget *parent = Q_NULLPTR);
+ explicit PreviewForm(QWidget *parent = nullptr);
void setCodecList(const QList<QTextCodec *> &list);
void setEncodedData(const QByteArray &data);
diff --git a/examples/widgets/tools/completer/fsmodel.h b/examples/widgets/tools/completer/fsmodel.h
index a243c48b43..7b2e7b7dab 100644
--- a/examples/widgets/tools/completer/fsmodel.h
+++ b/examples/widgets/tools/completer/fsmodel.h
@@ -55,7 +55,7 @@
// With a QFileSystemModel, set on a view, you will see "Program Files" in the view
// But with this model, you will see "C:\Program Files" in the view.
-// We acheive this, by having the data() return the entire file path for
+// We achieve this, by having the data() return the entire file path for
// the display role. Note that the Qt::EditRole over which the QCompleter
// looks for matches is left unchanged
//! [0]
diff --git a/examples/widgets/tools/settingseditor/mainwindow.cpp b/examples/widgets/tools/settingseditor/mainwindow.cpp
index ab9837c513..a7a1e9b415 100644
--- a/examples/widgets/tools/settingseditor/mainwindow.cpp
+++ b/examples/widgets/tools/settingseditor/mainwindow.cpp
@@ -56,7 +56,7 @@
MainWindow::MainWindow()
: settingsTree(new SettingsTree)
- , locationDialog(Q_NULLPTR)
+ , locationDialog(nullptr)
{
setCentralWidget(settingsTree);
diff --git a/examples/widgets/widgets/charactermap/characterwidget.cpp b/examples/widgets/widgets/charactermap/characterwidget.cpp
index 55d45501f1..5bab921516 100644
--- a/examples/widgets/widgets/charactermap/characterwidget.cpp
+++ b/examples/widgets/widgets/charactermap/characterwidget.cpp
@@ -181,7 +181,7 @@ void CharacterWidget::paintEvent(QPaintEvent *event)
if (key == lastKey)
painter.fillRect(column*squareSize + 1, row*squareSize + 1, squareSize, squareSize, QBrush(Qt::red));
- painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.width(QChar(key))/2,
+ painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.horizontalAdvance(QChar(key))/2,
row*squareSize + 4 + fontMetrics.ascent(),
QString(QChar(key)));
}
diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp
index 5f17128a2f..d3ac55483c 100644
--- a/examples/widgets/widgets/charactermap/mainwindow.cpp
+++ b/examples/widgets/widgets/charactermap/mainwindow.cpp
@@ -244,7 +244,7 @@ void MainWindow::updateClipboard()
class FontInfoDialog : public QDialog
{
public:
- explicit FontInfoDialog(QWidget *parent = Q_NULLPTR);
+ explicit FontInfoDialog(QWidget *parent = nullptr);
private:
QString text() const;
diff --git a/examples/widgets/widgets/codeeditor/codeeditor.cpp b/examples/widgets/widgets/codeeditor/codeeditor.cpp
index 69974e72be..7e56a75294 100644
--- a/examples/widgets/widgets/codeeditor/codeeditor.cpp
+++ b/examples/widgets/widgets/codeeditor/codeeditor.cpp
@@ -79,7 +79,7 @@ int CodeEditor::lineNumberAreaWidth()
++digits;
}
- int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
+ int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
return space;
}
diff --git a/examples/widgets/widgets/icons/iconpreviewarea.cpp b/examples/widgets/widgets/icons/iconpreviewarea.cpp
index 35379610c5..9cb54c47f6 100644
--- a/examples/widgets/widgets/icons/iconpreviewarea.cpp
+++ b/examples/widgets/widgets/icons/iconpreviewarea.cpp
@@ -190,7 +190,7 @@ QLabel *IconPreviewArea::createPixmapLabel()
//! [5]
void IconPreviewArea::updatePixmapLabels()
{
- QWindow *window = Q_NULLPTR;
+ QWindow *window = nullptr;
if (const QWidget *nativeParent = nativeParentWidget())
window = nativeParent->windowHandle();
for (int column = 0; column < NumModes; ++column) {
diff --git a/examples/widgets/widgets/icons/iconpreviewarea.h b/examples/widgets/widgets/icons/iconpreviewarea.h
index 3ebb9ed3ce..6ea35a5230 100644
--- a/examples/widgets/widgets/icons/iconpreviewarea.h
+++ b/examples/widgets/widgets/icons/iconpreviewarea.h
@@ -66,7 +66,7 @@ class IconPreviewArea : public QWidget
Q_OBJECT
public:
- explicit IconPreviewArea(QWidget *parent = Q_NULLPTR);
+ explicit IconPreviewArea(QWidget *parent = nullptr);
void setIcon(const QIcon &icon);
void setSize(const QSize &size);
diff --git a/examples/widgets/widgets/icons/iconsizespinbox.h b/examples/widgets/widgets/icons/iconsizespinbox.h
index 96a56e75c9..87415ac5d6 100644
--- a/examples/widgets/widgets/icons/iconsizespinbox.h
+++ b/examples/widgets/widgets/icons/iconsizespinbox.h
@@ -59,7 +59,7 @@ class IconSizeSpinBox : public QSpinBox
Q_OBJECT
public:
- explicit IconSizeSpinBox(QWidget *parent = Q_NULLPTR);
+ explicit IconSizeSpinBox(QWidget *parent = nullptr);
int valueFromText(const QString &text) const override;
QString textFromValue(int value) const override;
diff --git a/examples/widgets/widgets/icons/imagedelegate.h b/examples/widgets/widgets/icons/imagedelegate.h
index 928085d85b..3b76b78339 100644
--- a/examples/widgets/widgets/icons/imagedelegate.h
+++ b/examples/widgets/widgets/icons/imagedelegate.h
@@ -59,7 +59,7 @@ class ImageDelegate : public QItemDelegate
Q_OBJECT
public:
- explicit ImageDelegate(QObject *parent = Q_NULLPTR);
+ explicit ImageDelegate(QObject *parent = nullptr);
//! [0]
//! [1]
diff --git a/examples/widgets/widgets/tablet/mainwindow.cpp b/examples/widgets/widgets/tablet/mainwindow.cpp
index feae16dd83..994666d4de 100644
--- a/examples/widgets/widgets/tablet/mainwindow.cpp
+++ b/examples/widgets/widgets/tablet/mainwindow.cpp
@@ -55,7 +55,7 @@
//! [0]
MainWindow::MainWindow(TabletCanvas *canvas)
- : m_canvas(canvas), m_colorDialog(Q_NULLPTR)
+ : m_canvas(canvas), m_colorDialog(nullptr)
{
createMenus();
setWindowTitle(tr("Tablet Example"));
diff --git a/examples/widgets/widgets/tablet/tabletcanvas.cpp b/examples/widgets/widgets/tablet/tabletcanvas.cpp
index 4b11568dfe..73678ab754 100644
--- a/examples/widgets/widgets/tablet/tabletcanvas.cpp
+++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp
@@ -55,7 +55,7 @@
//! [0]
TabletCanvas::TabletCanvas()
- : QWidget(Q_NULLPTR)
+ : QWidget(nullptr)
, m_alphaChannelValuator(TangentialPressureValuator)
, m_colorSaturationValuator(NoValuator)
, m_lineWidthValuator(PressureValuator)
@@ -119,12 +119,12 @@ void TabletCanvas::tabletEvent(QTabletEvent *event)
case QEvent::TabletRelease:
if (m_deviceDown && event->buttons() == Qt::NoButton)
m_deviceDown = false;
+ update();
break;
default:
break;
}
event->accept();
- update();
}
//! [3]
@@ -154,6 +154,7 @@ void TabletCanvas::paintEvent(QPaintEvent *)
//! [5]
void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
{
+ static qreal maxPenRadius = pressureToWidth(1.0);
painter.setRenderHint(QPainter::Antialiasing);
switch (event->device()) {
@@ -169,6 +170,7 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
painter.setBrush(grad);
qreal radius = grad.radius();
painter.drawEllipse(event->posF(), radius, radius);
+ update(QRect(event->pos() - QPoint(radius, radius), QSize(radius * 2, radius * 2)));
}
break;
case QTabletEvent::RotationStylus:
@@ -188,6 +190,7 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
poly << event->posF() - brushAdjust;
poly << event->posF() + brushAdjust;
painter.drawConvexPolygon(poly);
+ update(poly.boundingRect().toRect());
}
break;
//! [6]
@@ -217,6 +220,8 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
case QTabletEvent::Stylus:
painter.setPen(m_pen);
painter.drawLine(lastPoint.pos, event->posF());
+ update(QRect(lastPoint.pos.toPoint(), event->pos()).normalized()
+ .adjusted(-maxPenRadius, -maxPenRadius, maxPenRadius, maxPenRadius));
break;
}
}
diff --git a/examples/widgets/widgets/tablet/tabletcanvas.h b/examples/widgets/widgets/tablet/tabletcanvas.h
index a1b31c65bf..671d5376f8 100644
--- a/examples/widgets/widgets/tablet/tabletcanvas.h
+++ b/examples/widgets/widgets/tablet/tabletcanvas.h
@@ -103,7 +103,7 @@ private:
void initPixmap();
void paintPixmap(QPainter &painter, QTabletEvent *event);
Qt::BrushStyle brushPattern(qreal value);
- qreal pressureToWidth(qreal pressure);
+ static qreal pressureToWidth(qreal pressure);
void updateBrush(const QTabletEvent *event);
void updateCursor(const QTabletEvent *event);
diff --git a/examples/widgets/widgets/wiggly/wigglywidget.cpp b/examples/widgets/widgets/wiggly/wigglywidget.cpp
index 9dfd43ff77..1b8f3cffad 100644
--- a/examples/widgets/widgets/wiggly/wigglywidget.cpp
+++ b/examples/widgets/widgets/wiggly/wigglywidget.cpp
@@ -77,7 +77,7 @@ void WigglyWidget::paintEvent(QPaintEvent * /* event */)
};
QFontMetrics metrics(font());
- int x = (width() - metrics.width(text)) / 2;
+ int x = (width() - metrics.horizontalAdvance(text)) / 2;
int y = (height() + metrics.ascent() - metrics.descent()) / 2;
QColor color;
//! [2]
@@ -91,7 +91,7 @@ void WigglyWidget::paintEvent(QPaintEvent * /* event */)
painter.setPen(color);
painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400),
QString(text[i]));
- x += metrics.width(text[i]);
+ x += metrics.horizontalAdvance(text[i]);
}
}
//! [4]