更新代码

This commit is contained in:
feiyangqingyun
2024-04-21 14:41:12 +08:00
parent 41188deae0
commit 47835c1fbe
18 changed files with 599 additions and 239 deletions

View File

@@ -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;
}
}