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

View File

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