Qt 4:移动没有标题栏的窗口 [英] Qt 4: Move window without title bar
本文介绍了Qt 4:移动没有标题栏的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个标记为Qt::Popup
的窗口(没有标题栏和关闭等按钮),并且想要通过拖动\单击非标题栏区域来移动....
I have a Qt::Popup
flagged window (which does not have a title bar and close etc buttons) and would like to move by dragging\clicking on the non-title bar area....
在Win32上,解决方案可以是 WM_NCLBUTTONDOWN ,但我的要求是跨平台.
On Win32, the solution could be WM_NCLBUTTONDOWN but my requirement is crossplatform.
推荐答案
尝试以下操作以手动移动窗口:
Try this to move the window manually:
void PopupWindow::mousePressEvent(QMouseEvent *event){
mpos = event->pos();
}
void PopupWindow::mouseMoveEvent(QMouseEvent *event){
if (event->buttons() & Qt::LeftButton) {
QPoint diff = event->pos() - mpos;
QPoint newpos = this->pos() + diff;
this->move(newpos);
}
}
然后在某处声明QPoint mpos
.
这篇关于Qt 4:移动没有标题栏的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文