QMessageBox wanders across the screen
-
Hi
I have the following code in an application using Qt5.1.1 under Mac OS X 10.8.5. This is to bring up a small message box and accept one of two input alternatives. The box which appears is in a different place on the screen each time. It walks downwards and to the right on each invocation. Does anyone know why this happens and/or how to stop it wandering? The same code run under Linux (F19) keeps the message box in the same place.
@
#include <QMessageBox>
#include "mainwindow.h"void MainWindow::step(Grid *p)
{
reDraw(p); // display latest positionQString msgstr = tr("After %1.").arg(strategyName);
statusBar()->showMessage(msgstr); // show strategy used
QMessageBox step(0,
tr(" Step?"),
QMessageBox::NoIcon,
QMessageBox::Ok |QMessageBox::Default,
QMessageBox::Cancel|QMessageBox::Escape,
QMessageBox::NoButton);if (step.exec() == QMessageBox::Cancel)
setRun();
}
@ -
It's probably an OS behavior that tries to show it in the "most proper area", which might change every time. Not a big deal, it's always meant to appear on the user visible screen, no matter where.
Anyway, if you really want to set it to appear somewhere specific you may claculate the xPos, yPos coordinates and then use QMessageBox::move(xPos, yPos); -
Thanks T3sty. As it was platform dependent I assumed there was a good reason for the strange behaviour. Odd that the position is progressive though.
I'll give the ::move() method a try.
Thanks again.
-
... except QMessageBox doesn't have a function move according to Assistant ...
-
Whoops! Yes it does. I beg your pardon.
-
No problem :)
For people who are not familiar with this, the move() function is inherited from the main QWidget class, and it's a common function for all the widgets in Qt. -
However, when I inserted a line:
@
step.move(100,100);
@in front of the
@
if (step.exec() == QMessageBox::Cancel)
@it had no effect on the behaviour of the QMessageBox window.
So no further forward.