7

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....

On Win32, the solution could be WM_NCLBUTTONDOWN but my requirement is crossplatform.

yolo
  • 2,757
  • 6
  • 36
  • 65

2 Answers2

19

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);
    }
}

And declare QPoint mpos somewhere.

Dmitry Sazonov
  • 8,801
  • 1
  • 35
  • 61
Karsten
  • 1,814
  • 2
  • 17
  • 32
6
if (event->buttons() && Qt::LeftButton) {

this condition is true for every mouse button

maybe you kept in mind this

if (event->buttons() & Qt::LeftButton) {
Cyxx
  • 61
  • 1
  • 1