Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_corelib_tools_qpoint.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QPoint>
5#include <QMouseEvent>
6#include <iostream>
7
8int x() { return 0; }
9
10int y() { return 0; }
11
13{
14
15 {
16 //! [0]
17 QPoint p;
18
19 p.setX(p.x() + 1);
20 p += QPoint(1, 0);
21 p.rx()++;
22 //! [0]
23 }
24
25 {
26 //! [1]
27 QPoint p(1, 2);
28 p.rx()--; // p becomes (0, 2)
29 //! [1]
30 }
31
32 {
33 //! [2]
34 QPoint p(1, 2);
35 p.ry()++; // p becomes (1, 3)
36 //! [2]
37 }
38
39 {
40 //! [3]
41 QPoint p( 3, 7);
42 QPoint q(-1, 4);
43 p += q; // p becomes (2, 11)
44 //! [3]
45 }
46
47 {
48 //! [4]
49 QPoint p( 3, 7);
50 QPoint q(-1, 4);
51 p -= q; // p becomes (4, 3)
52 //! [4]
53 }
54
55 {
56 //! [5]
57 QPoint p(-1, 4);
58 p *= 2.5; // p becomes (-3, 10)
59 //! [5]
60 }
61
62 {
63 //! [16]
64 QPoint p( 3, 7);
65 QPoint q(-1, 4);
66 int dotProduct = QPoint::dotProduct(p, q); // dotProduct becomes 25
67 //! [16]
68 }
69
70 {
71 //! [6]
72 QPoint p(-3, 10);
73 p /= 2.5; // p becomes (-1, 4)
74 //! [6]
75 }
76
77 {
78 //! [8]
79 double trueLength = std::sqrt(std::pow(x(), 2) + std::pow(y(), 2));
80 //! [8]
81 }
82
83 {
84 //! [9]
85 QPointF p;
86
87 p.setX(p.x() + 1.0);
88 p += QPointF(1.0, 0.0);
89 p.rx()++;
90 //! [9]
91 }
92
93 {
94 //! [10]
95 QPointF p(1.1, 2.5);
96 p.rx()--; // p becomes (0.1, 2.5)
97 //! [10]
98 }
99
100 {
101 //! [11]
102 QPointF p(1.1, 2.5);
103 p.ry()++; // p becomes (1.1, 3.5)
104 //! [11]
105 }
106
107 {
108 //! [12]
109 QPointF p( 3.1, 7.1);
110 QPointF q(-1.0, 4.1);
111 p += q; // p becomes (2.1, 11.2)
112 //! [12]
113 }
114
115 {
116 //! [13]
117 QPointF p( 3.1, 7.1);
118 QPointF q(-1.0, 4.1);
119 p -= q; // p becomes (4.1, 3.0)
120 //! [13]
121 }
122
123 {
124 //! [14]
125 QPointF p(-1.1, 4.1);
126 p *= 2.5; // p becomes (-2.75, 10.25)
127 //! [14]
128 }
129
130 {
131 //! [15]
132 QPointF p(-2.75, 10.25);
133 p /= 2.5; // p becomes (-1.1, 4.1)
134 //! [15]
135 }
136
137 {
138 //! [17]
139 QPointF p( 3.1, 7.1);
140 QPointF q(-1.0, 4.1);
141 qreal dotProduct = QPointF::dotProduct(p, q); // dotProduct becomes 26.01
142 //! [17]
143 }
144}
145
146class MyWidget
147{
148public:
149 void mouseMoveEvent(QMouseEvent *event);
150};
151
152//! [7]
154
155void MyWidget::mouseMoveEvent(QMouseEvent *event)
156{
157 QPoint point = event->pos() - oldPosition;
158 if (point.manhattanLength() > 3){
159 // the mouse has moved more than 3 pixels since the oldPosition
160 }
161}
162//! [7]
void mouseMoveEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
bool examples()
[3]
QPoint oldPosition
[7]