Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMessageBox wanders across the screen
Forum Update on Monday, May 27th 2025

QMessageBox wanders across the screen

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    smiffy
    wrote on last edited by
    #1

    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 position

    QString 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();
    }
    @

    1 Reply Last reply
    0
    • T3STYT Offline
      T3STYT Offline
      T3STY
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        smiffy
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          smiffy
          wrote on last edited by
          #4

          ... except QMessageBox doesn't have a function move according to Assistant ...

          1 Reply Last reply
          0
          • S Offline
            S Offline
            smiffy
            wrote on last edited by
            #5

            Whoops! Yes it does. I beg your pardon.

            1 Reply Last reply
            0
            • T3STYT Offline
              T3STYT Offline
              T3STY
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                smiffy
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved