更新代码
This commit is contained in:
@@ -24,7 +24,7 @@ AppInit::AppInit(QObject *parent) : QObject(parent)
|
||||
}
|
||||
|
||||
bool AppInit::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
{
|
||||
QWidget *w = (QWidget *)watched;
|
||||
if (!w->property("canMove").toBool()) {
|
||||
return QObject::eventFilter(watched, event);
|
||||
@@ -34,26 +34,17 @@ bool AppInit::eventFilter(QObject *watched, QEvent *event)
|
||||
static bool mousePressed = false;
|
||||
|
||||
int type = event->type();
|
||||
QPoint p;
|
||||
QMouseEvent *mouseEvent = (QMouseEvent *)(event);
|
||||
if (mouseEvent) {
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
p = mouseEvent->globalPos();
|
||||
#else
|
||||
p = mouseEvent->globalPosition().toPoint();
|
||||
#endif
|
||||
}
|
||||
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (type == QEvent::MouseButtonPress) {
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
mousePressed = true;
|
||||
mousePoint = p - w->pos();
|
||||
mousePoint = mouseEvent->globalPos() - w->pos();
|
||||
}
|
||||
} else if (type == QEvent::MouseButtonRelease) {
|
||||
mousePressed = false;
|
||||
} else if (type == QEvent::MouseMove) {
|
||||
if (mousePressed) {
|
||||
w->move(p - mousePoint);
|
||||
w->move(mouseEvent->globalPos() - mousePoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user