1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-18 08:22:33 +02:00

Fix widget moving jitter thanks to bardao https://stackoverflow.com/a/55367441/12619313

This commit is contained in:
Elias Steurer 2020-01-10 20:54:27 +01:00
parent 1c3d89cc2f
commit 369b01ac9b
3 changed files with 12 additions and 9 deletions

View File

@ -83,15 +83,21 @@ Item {
MouseArea {
id: mouseArea
property var clickPos
anchors.fill: parent
hoverEnabled: true
onPressed: {
Widget.setClickPos(Qt.point(mouse.x, mouse.y))
clickPos = {
"x": mouse.x,
"y": mouse.y
}
}
onPositionChanged: {
if (mouseArea.pressed)
Widget.setPos(mouse.x, mouse.y)
if (mouseArea.pressed) {
Widget.setPos(Widget.cursorPos().x - clickPos.x,
Widget.cursorPos().y - clickPos.y)
}
}
}

View File

@ -76,12 +76,7 @@ void WidgetWindow::messageReceived(QString key, QString value)
void WidgetWindow::setPos(int xPos, int yPos)
{
QPoint delta((xPos - m_clickPos.x()), (yPos - m_clickPos.y()));
int new_x = m_window.x() + delta.x();
int new_y = m_window.y() + delta.y();
m_window.setPosition(QPoint(new_x, new_y));
m_window.setPosition({ xPos, yPos });
}
void WidgetWindow::setClickPos(const QPoint& clickPos)

View File

@ -102,6 +102,7 @@ public slots:
emit sourcePathChanged(m_sourcePath);
}
QPointF cursorPos() { return QCursor::pos(); }
#ifdef Q_OS_WIN
void setWindowBlur(unsigned int style = 3);
#endif
@ -114,6 +115,7 @@ private:
QJsonObject m_project;
QPoint m_clickPos = { 0, 0 };
QPoint m_lastPos = { 0, 0 };
QQuickView m_window;
#ifdef Q_OS_WIN