您的位置:首页 > 编程语言 > Qt开发

(1_255)Qt拖动没有标题栏的窗体

2013-06-19 14:58 211 查看
在main中:w.setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏;在*.h中:QPoint windowPos,mousePos,dPos;在*.cpp:void yourwindow::mousePressEvent(QMouseEvent *event){ this->windowPos = this->pos(); // pos()是相对于窗口的,以窗口左上角为原点(去除边框)。即pos()给出的是一个相对位置坐标。而globalPos(),给出的是一个绝对坐标。 this->mousePos = event->globalPos(); // globalpos()给出的坐标信息是相对于桌面的,即以桌面左上角为原点 this->dPos = mousePos - windowPos; }
void yourwindow::mouseMoveEvent(QMouseEvent *event){ this->move(event->globalPos() - this->dPos); }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: