summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorTang Haixiang <tanghaixiang@uniontech.com>2022-01-24 18:11:14 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-04-15 05:21:20 +0000
commit81f8f86c49955efc72b829682787e682bec44664 (patch)
tree4dc1bd0a54ab07c7f2629ba654ea472cb6227aac /examples/widgets
parent9458373cd0cd62ad929b062e4d69eddf3eee236b (diff)
Chip example: fix an accidental bool->int conversion when using PMF connections
The example was refactored to use the PMF connection syntax. However this introduced a problem: when connecting a QAbstractButton to a slot that has a default parameter, the semantics of the connection change between string-based connections and PMF. Specifically: when connecting the QAbstractButton::clicked(bool checked = false) signal to a slot like View::zoomIn(int level = 1) then a string-based connection like connect(button, SIGNAL(clicked()), this, SLOT(zoomIn())) would call zoomIn without carrying the signal's parameter over. In other words, zoomIn's parameter is defaulted. The same connection using PFM instead is connect(button, &QAbstractButton::clicked, this, &View::zoomIn) which would "connect" the arguments. This makes emissions that pass false as clicked's parameter result in a zoomIn by 0. Fix it by avoiding the default parameter of zoomIn -- just split the function in two (zoomIn and zoomInBy). Amends 8cf812231405e011b422a1505d9a219618fe5cee. Fixes: QTBUG-100135 Done-with: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Change-Id: I10c150c648034449e3154140108de2d64326d965 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 7a7023b7b1693ceaafcbafb30d41fb3a4c820a90) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/graphicsview/chip/view.cpp18
-rw-r--r--examples/widgets/graphicsview/chip/view.h6
2 files changed, 18 insertions, 6 deletions
diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp
index 186b24655b..736c9b6570 100644
--- a/examples/widgets/graphicsview/chip/view.cpp
+++ b/examples/widgets/graphicsview/chip/view.cpp
@@ -65,9 +65,9 @@ void GraphicsView::wheelEvent(QWheelEvent *e)
{
if (e->modifiers() & Qt::ControlModifier) {
if (e->angleDelta().y() > 0)
- view->zoomIn(6);
+ view->zoomInBy(6);
else
- view->zoomOut(6);
+ view->zoomOutBy(6);
e->accept();
} else {
QGraphicsView::wheelEvent(e);
@@ -253,12 +253,22 @@ void View::print()
#endif
}
-void View::zoomIn(int level)
+void View::zoomIn()
+{
+ zoomSlider->setValue(zoomSlider->value() + 1);
+}
+
+void View::zoomOut()
+{
+ zoomSlider->setValue(zoomSlider->value() - 1);
+}
+
+void View::zoomInBy(int level)
{
zoomSlider->setValue(zoomSlider->value() + level);
}
-void View::zoomOut(int level)
+void View::zoomOutBy(int level)
{
zoomSlider->setValue(zoomSlider->value() - level);
}
diff --git a/examples/widgets/graphicsview/chip/view.h b/examples/widgets/graphicsview/chip/view.h
index b780702c34..5a200fa4f7 100644
--- a/examples/widgets/graphicsview/chip/view.h
+++ b/examples/widgets/graphicsview/chip/view.h
@@ -86,8 +86,10 @@ public:
QGraphicsView *view() const;
public slots:
- void zoomIn(int level = 1);
- void zoomOut(int level = 1);
+ void zoomIn();
+ void zoomOut();
+ void zoomInBy(int level);
+ void zoomOutBy(int level);
private slots:
void resetView();