设置边框隐藏 setWindowFlags(Qt::FramelessWindowHint);
监听鼠标事件
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
代码示例(本例为标题栏移动示例)
.h
#ifndef DLGABOUT
#define DLGABOUT
#include <QDialog>
#include <QMouseEvent>
#include "ui_DlgAbout.h"
class DlgAbout : public QDialog
{
Q_OBJECT
public:
DlgAbout(QWidget *parent = Q_NULLPTR);
~DlgAbout();
protected:
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
private:
Ui::DlgAbout ui;
bool m_bMove; //窗口是否正在移动
QPoint m_pressPoint;//鼠标按下去的坐标
};
#endif // !DlgAbout
.cpp
#include "DlgAbout.h"
#define TITLE_BAR_HEIGHT 50
DlgAbout::DlgAbout(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
//设置标题栏隐藏
this->setWindowFlags(Qt::FramelessWindowHint | Qt::