Search code examples
c++qtqt4qt4.8

qt prevent qdialog/window from moving with mainwindow


Env

  • OS X 10.6.8 ... and later, Windows XP ... and later.
  • Qt 4.7 (has to be, legacy issues, OS X 10.6.8 must be supported, Qt5 won't do it)

Problem

I have opened a second window in my application. It behaves as I want it to, except that if the MainWindow in the application moves, so does this window. That behavior is unwanted (actually more like "toxic and user-unfriendly").

The Qt docs say not to call move() from within moveEvent(), and anyway moveEvent() only shows up after window has stopped moving, not even while moving, which would, even if I did use it successfully, result in second window moving and snapping back, which would be pretty awful.

I thought to try overriding move() and not calling QDialog::move(), but that didn't work, it seems it cannot be overridden; rfview window still follows mainwindow around.

Perhaps I am opening the window wrong:

void MainWindow::xrfview()
{
    ttrfview = new rfview(this);
    uiframePlot = ttrfview->ui->framePlot;
    ttrfview->show();
    ttrfview->raise();
}

Or perhaps I have defined the window wrong:

class rfview: public QDialog
{
    Q_OBJECT

public:
    explicit rfview(QWidget *parent = 0);
    ~rfview();
}

Or both?

Basically, if the user drags/re-positions MainWindow, I do not want the rfview window to follow.


Solution

  • Change ttrfview = new rfview(this) to ttrfview = new rfview()