Made window moveable

This commit is contained in:
Pierre HUBERT 2020-06-12 15:19:50 +02:00
parent 416e6d44c5
commit 6b76aa3847
3 changed files with 25 additions and 2 deletions

View File

@ -20,3 +20,20 @@ void LoginWindow::on_closeButton_clicked()
{
this->close();
}
void LoginWindow::mousePressEvent(QMouseEvent *evt)
{
mOldPos = evt->globalPos();
}
void LoginWindow::mouseMoveEvent(QMouseEvent *evt)
{
const QPoint delta = evt->globalPos() - mOldPos;
if (false)
// if locked, ignore delta on y axis, stay at the top
move(x()+delta.x(), y());
else
move(x()+delta.x(), y()+delta.y());
mOldPos = evt->globalPos();
}

View File

@ -7,6 +7,7 @@
#pragma once
#include <QDialog>
#include <QMouseEvent>
QT_BEGIN_NAMESPACE
namespace Ui { class LoginWindow; }
@ -20,9 +21,14 @@ public:
LoginWindow(QWidget *parent = nullptr);
~LoginWindow();
protected:
void mousePressEvent(QMouseEvent *evt);
void mouseMoveEvent(QMouseEvent *evt);
private slots:
void on_closeButton_clicked();
private:
Ui::LoginWindow *ui;
QPoint mOldPos;
};

View File

@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>337</width>
<height>600</height>
<width>330</width>
<height>501</height>
</rect>
</property>
<property name="windowTitle">