summaryrefslogtreecommitdiffstats
path: root/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
diff options
context:
space:
mode:
authorTang Haixiang <tanghaixiang@uniontech.com>2021-10-29 11:40:46 +0800
committerShawn Rutledge <shawn.rutledge@qt.io>2021-11-03 01:10:32 +0000
commitf5eda09a639715036d48a60078e6a379ec151f94 (patch)
tree7dc4cff609ca5ec851c5293a365771674961edc3 /examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
parentace53d282d610dc2a4e96fbe1b84f5b39e93dc77 (diff)
Modify the target Square in the puzzle
targetSquare judges which square the position falls in. The point scaling calculation method should not be used. The return value of QPoint operator/ will be rounded up. Modified to separate the x and y of position to calculate. Fixes: QTBUG-81842 Change-Id: I70375185a78ba47efe01be3fd490e0fb0f456e17 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples/widgets/draganddrop/puzzle/puzzlewidget.cpp')
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
index 06dda9c29f..361c7e937b 100644
--- a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
+++ b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
@@ -199,8 +199,8 @@ void PuzzleWidget::paintEvent(QPaintEvent *event)
const QRect PuzzleWidget::targetSquare(const QPoint &position) const
{
- return QRect(position / pieceSize() * pieceSize(),
- QSize(pieceSize(), pieceSize()));
+ QPoint topLeft = QPoint(position.x() / pieceSize(), position.y() / pieceSize()) * pieceSize();
+ return QRect(topLeft, QSize(pieceSize(), pieceSize()));
}
int PuzzleWidget::pieceSize() const