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. QDialog position in MacOS and Windows
Qt 6.11 is out! See what's new in the release blog

QDialog position in MacOS and Windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.7k Views 1 Watching
  • 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.
  • Gilbert HsuG Offline
    Gilbert HsuG Offline
    Gilbert Hsu
    wrote on last edited by Gilbert Hsu
    #1

    Hi developers,
    I am using Qt5.7.1 writing program on both Windows and MacOS. The program uses QDialog to alert user to do something. There will be picture in the middle of screen, I need to move the QDialog away from the picture, but I am suffering that QDialog::setGeometry() is not working the same way on MacOS and Windows. If I simply use the following code:

    QDialog message(this);
    message.exec();
    

    The message dialog will on the middle of top of the screen on MacOS but is in the middle of screen on Windows. This will make my picture be covered by the message dialog, no matter the message dialog is in the middle of top of screen or middle (center) of the scree. Therefore I use setGeometry() or move() to move the dialog as following:

    // Get geometry of main widget (this) first, say main_rect, the main widget spans the whole screen with flag (Window|FramelessWindowHint|WindowStaysOnTopHint) and state (WindowFullScreen)
    QDialog message(this);
    QRect rect(main_rect.left(), main_rect.top() + (main_rect.height() / 3), message.width(), message.height());
    message.setWindowFlags(Dialog|FramelessWindowHint|WindowStaysOnTopHint|CustomizeWindowHint);
    message.setGeometry(rect);
    message.exec();
    

    On MacOs, the message dialog still stays at the same position (middle of top of screen) but on Windows, the message dialog moves to middle of left of screen as I desired.

    However, on MacOS, if I add show() and then move() as following, I can see the message dialog appears on the middle of the top of screen and then "jump" to the middle of left of the screen. On Windows, the box did move to left top of screen.

    QDialog message(this);
    QRect rect(main_rect.left(), main_rect.top() + (main_rect.height() / 3), message.width(), message.height());
    message.setWindowFlags(Dialog|FramelessWindowHint|WindowStaysOnTopHint|CustomizeWindowHint);
    message.setGeometry(rect);
    message.show();
    message.move(rect.left(), rect.top());  // any point will do
    message.exec();
    

    Does anyone has such situation about QDialog? Thanks in advance.

    jsulmJ 1 Reply Last reply
    0
    • Gilbert HsuG Gilbert Hsu

      Hi developers,
      I am using Qt5.7.1 writing program on both Windows and MacOS. The program uses QDialog to alert user to do something. There will be picture in the middle of screen, I need to move the QDialog away from the picture, but I am suffering that QDialog::setGeometry() is not working the same way on MacOS and Windows. If I simply use the following code:

      QDialog message(this);
      message.exec();
      

      The message dialog will on the middle of top of the screen on MacOS but is in the middle of screen on Windows. This will make my picture be covered by the message dialog, no matter the message dialog is in the middle of top of screen or middle (center) of the scree. Therefore I use setGeometry() or move() to move the dialog as following:

      // Get geometry of main widget (this) first, say main_rect, the main widget spans the whole screen with flag (Window|FramelessWindowHint|WindowStaysOnTopHint) and state (WindowFullScreen)
      QDialog message(this);
      QRect rect(main_rect.left(), main_rect.top() + (main_rect.height() / 3), message.width(), message.height());
      message.setWindowFlags(Dialog|FramelessWindowHint|WindowStaysOnTopHint|CustomizeWindowHint);
      message.setGeometry(rect);
      message.exec();
      

      On MacOs, the message dialog still stays at the same position (middle of top of screen) but on Windows, the message dialog moves to middle of left of screen as I desired.

      However, on MacOS, if I add show() and then move() as following, I can see the message dialog appears on the middle of the top of screen and then "jump" to the middle of left of the screen. On Windows, the box did move to left top of screen.

      QDialog message(this);
      QRect rect(main_rect.left(), main_rect.top() + (main_rect.height() / 3), message.width(), message.height());
      message.setWindowFlags(Dialog|FramelessWindowHint|WindowStaysOnTopHint|CustomizeWindowHint);
      message.setGeometry(rect);
      message.show();
      message.move(rect.left(), rect.top());  // any point will do
      message.exec();
      

      Does anyone has such situation about QDialog? Thanks in advance.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Gilbert-Hsu said in QDialog position in MacOS and Windows:

      QDialog message(this);

      What happens if you do not set parent (remove "this")?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Gilbert HsuG 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Gilbert-Hsu said in QDialog position in MacOS and Windows:

        QDialog message(this);

        What happens if you do not set parent (remove "this")?

        Gilbert HsuG Offline
        Gilbert HsuG Offline
        Gilbert Hsu
        wrote on last edited by
        #3

        @jsulm Thanks for you reply.
        Without setting parent, the message dialog can be positioned as what I desired, but when the program loses focus, the message dialog is disappear (only the full screen base widget left on screen). I need the dialog to stay on top of the screen (stick to the full screen base widget). AFAIK, the QDialog::exec() is Application Modal in default, which is true when the application gets focus, but I've tried Qt::WindowModal as well as Qt::ApplicationModal, they both act the same, when the program loses focus, the message dialog disappears or is covered by the base full screen widget.

        jsulmJ 1 Reply Last reply
        0
        • Gilbert HsuG Gilbert Hsu

          @jsulm Thanks for you reply.
          Without setting parent, the message dialog can be positioned as what I desired, but when the program loses focus, the message dialog is disappear (only the full screen base widget left on screen). I need the dialog to stay on top of the screen (stick to the full screen base widget). AFAIK, the QDialog::exec() is Application Modal in default, which is true when the application gets focus, but I've tried Qt::WindowModal as well as Qt::ApplicationModal, they both act the same, when the program loses focus, the message dialog disappears or is covered by the base full screen widget.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Gilbert-Hsu exec() should actually force the dialog to be always on top of the application window. Try tor remove your setWindowFlags() call to see whether this makes a difference.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Gilbert HsuG 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Gilbert-Hsu exec() should actually force the dialog to be always on top of the application window. Try tor remove your setWindowFlags() call to see whether this makes a difference.

            Gilbert HsuG Offline
            Gilbert HsuG Offline
            Gilbert Hsu
            wrote on last edited by Gilbert Hsu
            #5

            @jsulm Not mentioned the style, there's no difference between removing setWindowFlags() and not setting parent to the message dialog. The message dialog is gone when the application loses focus and back again when I click on the application. I mean this is on Xcode over MacOS.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              AFAIR, window modal dialogs on macOS always have the same position as they are tied to the windows they are modal from. Qt follows correctly the macOS human interface guidelines .

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              Gilbert HsuG 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                AFAIR, window modal dialogs on macOS always have the same position as they are tied to the windows they are modal from. Qt follows correctly the macOS human interface guidelines .

                Gilbert HsuG Offline
                Gilbert HsuG Offline
                Gilbert Hsu
                wrote on last edited by
                #7

                @SGaist Yes, I agree that the window modal dialogs on MacOS always have the same position in order to comply with MacOS UI. AFAIK, I can only think of QDialog to wait user to click button so that the program continues. If the QDialog cannot be moved, do you have any suggestions about how to popup a "dialog" and wait for user action?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Do you mean you want to have the application event loop continuing as normal ?
                  If so, then use the open slot rather than exec. You will have to adapt the logic a bit for that.
                  If not, then I am not sure I am following your requirements. macOS users do not expect to have blocking dialogs other that the usual you have seen in the guidelines.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Gilbert HsuG 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Do you mean you want to have the application event loop continuing as normal ?
                    If so, then use the open slot rather than exec. You will have to adapt the logic a bit for that.
                    If not, then I am not sure I am following your requirements. macOS users do not expect to have blocking dialogs other that the usual you have seen in the guidelines.

                    Gilbert HsuG Offline
                    Gilbert HsuG Offline
                    Gilbert Hsu
                    wrote on last edited by
                    #9

                    @SGaist No, the application event loop should wait for user to click button on the message dialog to continue. I quit trying to repositioning the QDialog, I change to simply use Object and QEventLoop to achieve this goal. Thanks for your answer :)

                    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