diff options
Diffstat (limited to 'examples/widgets/widgets')
11 files changed, 18 insertions, 13 deletions
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] |