- 设置窗口无边框并始终保持在所有其他窗口的顶部
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
2.创建变量存储位置
QPoint m_dragPosition;
3.对鼠标左键按下和移动事件做处理
void mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { m_dragPosition = event->globalPos() - frameGeometry().topLeft(); raise(); event->accept(); } } void mouseMoveEvent(QMouseEvent *event) { if (event->buttons() & Qt::LeftButton) { move(event->globalPos() - m_dragPosition); event->accept(); } }