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