Skip to content

Commit 64d4cb4

Browse files
Qt6 compatibility
- Added code compatibility for Qt6; - Replaced deprecated calls (Qt6 only): - MouseEvent::globalPos -> MouseEvent::globalPosition::toPoint; - MouseEvent::globalX -> MouseEvent::globalPosition::toPoint::x; - MouseEvent::globalY -> MouseEvent::globalPosition::toPoint::y. - Applied code macro when necessary. - Updated code samples.
1 parent ab4e3a8 commit 64d4cb4

14 files changed

Lines changed: 103 additions & 35 deletions

File tree

sample/CustomFrame-Dynamic/customwindow/qcustomtitlebar.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 5 of September of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -30,16 +30,31 @@
3030
#include <QEvent>
3131
#include <QLabel>
3232
#include <QPoint>
33+
#include <QPointF>
3334
#include <QPixmap>
3435
#include <QWidget>
3536
#include <QPainter>
37+
#include <QtGlobal>
3638
#include <QMainWindow>
3739
#include <QHBoxLayout>
3840
#include <QMouseEvent>
3941
#include <QPaintEvent>
4042
#include <QPushButton>
4143
#include <QStyleOption>
4244

45+
#ifndef EV_GLOBAL_MACRO
46+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
47+
#define EV_GLOBAL_X(event) event->globalX()
48+
#define EV_GLOBAL_Y(event) event->globalY()
49+
#define EV_GLOBAL_POS(event) event->globalPos()
50+
#else
51+
#define EV_GLOBAL_X(event) event->globalPosition().toPoint().x()
52+
#define EV_GLOBAL_Y(event) event->globalPosition().toPoint().y()
53+
#define EV_GLOBAL_POS(event) event->globalPosition().toPoint()
54+
#endif
55+
#define EV_GLOBAL_MACRO
56+
#endif
57+
4358
namespace QCustomAttrs {
4459
enum WindowButton {
4560
Minimize = 0x01,

sample/CustomFrame-Dynamic/customwindow/qcustomwindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 4 of September of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -30,13 +30,15 @@
3030
#include <QTimer>
3131
#include <QPoint>
3232
#include <QStyle>
33+
#include <QPointF>
3334
#include <QObject>
3435
#include <QWidget>
3536
#include <QCursor>
3637
#include <QWindow>
3738
#include <QMenuBar>
3839
#include <QPainter>
3940
#include <QToolBar>
41+
#include <QtGlobal>
4042
#include <QStatusBar>
4143
#include <QSizePolicy>
4244
#include <QMetaMethod>

sample/CustomFrame-Static/customwindow/qcustomtitlebar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 5 of September of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -118,12 +118,12 @@ void QCustomTitleBar::setWindowButtonEnabled(QCustomAttrs::WindowButton btn, boo
118118
}
119119

120120
void QCustomTitleBar::mouseMoveEvent(QMouseEvent *event){
121-
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(event->globalPos());
121+
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(EV_GLOBAL_POS(event));
122122
QWidget::mouseMoveEvent(event);
123123
}
124124

125125
void QCustomTitleBar::mousePressEvent(QMouseEvent *event){
126-
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(event->globalPos());
126+
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(EV_GLOBAL_POS(event));
127127
QWidget::mousePressEvent(event);
128128
}
129129

sample/CustomFrame-Static/customwindow/qcustomtitlebar.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 5 of September of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -22,16 +22,31 @@
2222
#include <QEvent>
2323
#include <QLabel>
2424
#include <QPoint>
25+
#include <QPointF>
2526
#include <QPixmap>
2627
#include <QWidget>
2728
#include <QPainter>
29+
#include <QtGlobal>
2830
#include <QMainWindow>
2931
#include <QHBoxLayout>
3032
#include <QMouseEvent>
3133
#include <QPaintEvent>
3234
#include <QPushButton>
3335
#include <QStyleOption>
3436

37+
#ifndef EV_GLOBAL_MACRO
38+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
39+
#define EV_GLOBAL_X(event) event->globalX()
40+
#define EV_GLOBAL_Y(event) event->globalY()
41+
#define EV_GLOBAL_POS(event) event->globalPos()
42+
#else
43+
#define EV_GLOBAL_X(event) event->globalPosition().toPoint().x()
44+
#define EV_GLOBAL_Y(event) event->globalPosition().toPoint().y()
45+
#define EV_GLOBAL_POS(event) event->globalPosition().toPoint()
46+
#endif
47+
#define EV_GLOBAL_MACRO
48+
#endif
49+
3550
namespace QCustomAttrs {
3651
enum WindowButton {
3752
Minimize = 0x01,

sample/CustomFrame-Static/customwindow/qcustomwindow.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 5 of September of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -118,20 +118,20 @@ bool QCustomWindow::eventFilter(QObject *, QEvent *event){
118118
case QEvent::MouseMove:
119119
if (this->cOpStatus & OperationType::CUSTOM_RESIZE)
120120
customMouseMoveEvent(static_cast<QMouseEvent*>(event));
121-
else if (!this->isMoving()) redefineCursor(static_cast<QMouseEvent*>(event)->globalPos());
121+
else if (!this->isMoving()) redefineCursor(EV_GLOBAL_POS(static_cast<QMouseEvent*>(event)));
122122
break;
123123
default: break;
124124
}
125125
return false;
126126
}
127127

128128
void QCustomWindow::mousePressEvent(QMouseEvent *event){
129-
this->redefineCursor(event->globalPos());
129+
this->redefineCursor(EV_GLOBAL_POS(event));
130130
if (event->button() & Qt::LeftButton && this->mLock){
131131
if (!this->forceCustomResize && this->windowHandle()->startSystemResize(this->mLock))
132132
this->cOpStatus = OperationType::SYSTEM_RESIZE;
133133
else {
134-
QPoint posCursor = event->globalPos();
134+
QPoint posCursor = EV_GLOBAL_POS(event);
135135
if (this->mLock & Qt::TopEdge) posCursor.ry() -= this->y();
136136
if (this->mLock & Qt::LeftEdge) posCursor.rx() -= this->x();
137137
if (this->mLock & Qt::RightEdge) posCursor.rx() -= (this->x() + this->width());
@@ -144,12 +144,12 @@ void QCustomWindow::mousePressEvent(QMouseEvent *event){
144144

145145
void QCustomWindow::mouseReleaseEvent(QMouseEvent *event){
146146
this->cOpStatus = OperationType::NONE;
147-
this->redefineCursor(event->globalPos());
147+
this->redefineCursor(EV_GLOBAL_POS(event));
148148
QWidget::mouseReleaseEvent(event);
149149
}
150150

151151
void QCustomWindow::customMouseMoveEvent(QMouseEvent *event){
152-
int gX = event->globalX(), gY = event->globalY();
152+
int gX = EV_GLOBAL_X(event), gY = EV_GLOBAL_Y(event);
153153
QPoint tL = this->geometry().topLeft(), bR = this->geometry().bottomRight();
154154

155155
bool cRH = bR.x() - tL.x() > this->minimumWidth();

sample/CustomFrame-Static/customwindow/qcustomwindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 30 of August of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -22,13 +22,15 @@
2222
#include <QTimer>
2323
#include <QPoint>
2424
#include <QStyle>
25+
#include <QPointF>
2526
#include <QObject>
2627
#include <QWidget>
2728
#include <QCursor>
2829
#include <QWindow>
2930
#include <QMenuBar>
3031
#include <QPainter>
3132
#include <QToolBar>
33+
#include <QtGlobal>
3234
#include <QStatusBar>
3335
#include <QSizePolicy>
3436
#include <QMetaMethod>

src/QCustomWindow-Dynamic/qcustomtitlebar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 5 of September of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -118,12 +118,12 @@ void QCustomTitleBar::setWindowButtonEnabled(QCustomAttrs::WindowButton btn, boo
118118
}
119119

120120
void QCustomTitleBar::mouseMoveEvent(QMouseEvent *event){
121-
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(event->globalPos());
121+
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(EV_GLOBAL_POS(event));
122122
QWidget::mouseMoveEvent(event);
123123
}
124124

125125
void QCustomTitleBar::mousePressEvent(QMouseEvent *event){
126-
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(event->globalPos());
126+
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(EV_GLOBAL_POS(event));
127127
QWidget::mousePressEvent(event);
128128
}
129129

src/QCustomWindow-Dynamic/qcustomtitlebar.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 5 of September of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -30,16 +30,31 @@
3030
#include <QEvent>
3131
#include <QLabel>
3232
#include <QPoint>
33+
#include <QPointF>
3334
#include <QPixmap>
3435
#include <QWidget>
3536
#include <QPainter>
37+
#include <QtGlobal>
3638
#include <QMainWindow>
3739
#include <QHBoxLayout>
3840
#include <QMouseEvent>
3941
#include <QPaintEvent>
4042
#include <QPushButton>
4143
#include <QStyleOption>
4244

45+
#ifndef EV_GLOBAL_MACRO
46+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
47+
#define EV_GLOBAL_X(event) event->globalX()
48+
#define EV_GLOBAL_Y(event) event->globalY()
49+
#define EV_GLOBAL_POS(event) event->globalPos()
50+
#else
51+
#define EV_GLOBAL_X(event) event->globalPosition().toPoint().x()
52+
#define EV_GLOBAL_Y(event) event->globalPosition().toPoint().y()
53+
#define EV_GLOBAL_POS(event) event->globalPosition().toPoint()
54+
#endif
55+
#define EV_GLOBAL_MACRO
56+
#endif
57+
4358
namespace QCustomAttrs {
4459
enum WindowButton {
4560
Minimize = 0x01,

src/QCustomWindow-Dynamic/qcustomwindow.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 5 of September of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -118,20 +118,20 @@ bool QCustomWindow::eventFilter(QObject *, QEvent *event){
118118
case QEvent::MouseMove:
119119
if (this->cOpStatus & OperationType::CUSTOM_RESIZE)
120120
customMouseMoveEvent(static_cast<QMouseEvent*>(event));
121-
else if (!this->isMoving()) redefineCursor(static_cast<QMouseEvent*>(event)->globalPos());
121+
else if (!this->isMoving()) redefineCursor(EV_GLOBAL_POS(static_cast<QMouseEvent*>(event)));
122122
break;
123123
default: break;
124124
}
125125
return false;
126126
}
127127

128128
void QCustomWindow::mousePressEvent(QMouseEvent *event){
129-
this->redefineCursor(event->globalPos());
129+
this->redefineCursor(EV_GLOBAL_POS(event));
130130
if (event->button() & Qt::LeftButton && this->mLock){
131131
if (!this->forceCustomResize && this->windowHandle()->startSystemResize(this->mLock))
132132
this->cOpStatus = OperationType::SYSTEM_RESIZE;
133133
else {
134-
QPoint posCursor = event->globalPos();
134+
QPoint posCursor = EV_GLOBAL_POS(event);
135135
if (this->mLock & Qt::TopEdge) posCursor.ry() -= this->y();
136136
if (this->mLock & Qt::LeftEdge) posCursor.rx() -= this->x();
137137
if (this->mLock & Qt::RightEdge) posCursor.rx() -= (this->x() + this->width());
@@ -144,12 +144,12 @@ void QCustomWindow::mousePressEvent(QMouseEvent *event){
144144

145145
void QCustomWindow::mouseReleaseEvent(QMouseEvent *event){
146146
this->cOpStatus = OperationType::NONE;
147-
this->redefineCursor(event->globalPos());
147+
this->redefineCursor(EV_GLOBAL_POS(event));
148148
QWidget::mouseReleaseEvent(event);
149149
}
150150

151151
void QCustomWindow::customMouseMoveEvent(QMouseEvent *event){
152-
int gX = event->globalX(), gY = event->globalY();
152+
int gX = EV_GLOBAL_X(event), gY = EV_GLOBAL_Y(event);
153153
QPoint tL = this->geometry().topLeft(), bR = this->geometry().bottomRight();
154154

155155
bool cRH = bR.x() - tL.x() > this->minimumWidth();

src/QCustomWindow-Dynamic/qcustomwindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# Licence: Mozilla Public Licence 2.0
7-
# Date: 4 of September of 2021
7+
# Date: 31 of October of 2021
88
#
99
# Licence notice
1010
#
@@ -30,13 +30,15 @@
3030
#include <QTimer>
3131
#include <QPoint>
3232
#include <QStyle>
33+
#include <QPointF>
3334
#include <QObject>
3435
#include <QWidget>
3536
#include <QCursor>
3637
#include <QWindow>
3738
#include <QMenuBar>
3839
#include <QPainter>
3940
#include <QToolBar>
41+
#include <QtGlobal>
4042
#include <QStatusBar>
4143
#include <QSizePolicy>
4244
#include <QMetaMethod>

0 commit comments

Comments
 (0)