//去掉窗体的标题栏
this->setWindowFlags(Qt::FramelessWindowHint);
//重写鼠标事件,通过全局坐标进行定位和移动
void MainWindow::mousePressEvent(QMouseEvent *e)
{
last = e->globalPos();
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
int dx = e->globalX() - last.x();
int dy = e->globalY() - last.y();
last = e->globalPos();
move(this->x()+dx, this->y()+dy);
}
void MainWindow::mouseReleaseEvent(QMouseEvent *e)
{
int dx = e->globalX() - last.x();
int dy = e->globalY() - last.y();
move(this->x()+dx, this->y()+dy);
}
Qt—移动无边框窗体
最新推荐文章于 2024-07-01 18:34:35 发布