Qt 4: Moving a window without a title bar

I have a window with the Qt::Popup checkbox (which does not have a title bar and closing, etc.) and you want to move by dragging \ clicking on the area without a title ....

In Win32, the solution may be WM_NCLBUTTONDOWN , but my requirement is cross-platform.

+6
qt qt4 window popupwindow draggable
source share
2 answers

Try moving this 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); } } 

And declare QPoint mpos somewhere.

+14
source share
 if (event->buttons() && Qt::LeftButton) { 

This condition is true for each mouse button.

You may have remembered this

 if (event->buttons() & Qt::LeftButton) { 
+5
source share

All Articles