我有一个标记为
Qt::Popup
的窗口(没有标题栏和关闭按钮等),希望通过拖动/点击非标题栏区域来移动它....在Win32上,解决方案可能是WM_NCLBUTTONDOWN,但我的要求是跨平台的。Qt::Popup
的窗口(没有标题栏和关闭按钮等),希望通过拖动/点击非标题栏区域来移动它....在Win32上,解决方案可能是WM_NCLBUTTONDOWN,但我的要求是跨平台的。尝试手动移动窗口:
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
。
if (event->buttons() && Qt::LeftButton) {
这个条件对于每个鼠标按钮都成立。
也许你已经记住了这个。
if (event->buttons() & Qt::LeftButton) {