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. Positioning modal dialogs on MAC OSX... what's the trick?
Forum Updated to NodeBB v4.3 + New Features

Positioning modal dialogs on MAC OSX... what's the trick?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 3.8k 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.
  • K Offline
    K Offline
    kenchan
    wrote on last edited by
    #1

    Hello,

    I am using the QPrintPreviewDialog on Windows and the Mac OSX.

    I want to move it into a certain position and resize it before it is displayed. I do this using the move(...) and resize(...) methods before calling the exec() method. This works fine on Windows but not on OSX. OSX always puts the dialog in the middle of the screen, the size however is set to the size I set it to.

    Why the difference, Is this only a Mac thing? how can I force the window into a certain position?

    Does anyone have any good ideas?

    Many thanks.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      langi667
      wrote on last edited by
      #2

      Yes modal dialogs are centered on Mac OSX as far as I know, but you can change the size calling setGeometry like this:

      @dial->setGeometry(0,0,300,300);
      dial->exec();@

      1 Reply Last reply
      0
      • L Offline
        L Offline
        langi667
        wrote on last edited by
        #3

        if you really need to positionize it, you can put an EventLoop around your dialog call, this one worked fine, but don't know about side effects ;)

        @
        QDialog* dial = new QDialog();
        QEventLoop loop;

        dial->setGeometry(0,0,300,300);
        dial->show();

        QObject::connect( dial, SIGNAL(finished(int)), &loop, SLOT(quit()) );
        loop.exec();

        switch( dial->result() ){
        ...
        }
        @

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tusharkant15
          wrote on last edited by
          #4

          The purpose of modal dialogs is that dialogs are attached to the window that creates it. They minimize with the main window and move around with the main window.

          If you really want to position the window then you'll have to place the contents of your dialog in a separate window. But this will result in a behavior that's inconsistent with all other apps on the system. Which means that your app might get rejected on the mac app store.

          Gnome shell on linux has the same problem. I guess it's there to make sure the user doesn't loose some dialog in a mess of open windows but it sure limits what you can do as a developer.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kenchan
            wrote on last edited by
            #5

            Actually I want it to be attached to its parent and behave as a modal dialog does in all other respects. I just want to position it in a slightly different place in relation to its parent. Since it is an application modal I don't think there is any chance of it getting lost or anything like that.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kenchan
              wrote on last edited by
              #6

              Thank you for your suggestion langi667,

              I will try your idea and see if it fits in with what I am trying to do.

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

                Hi,

                If I may, I'd suggest that you don't try to modify an OS specific behavior like this one. OS X users know that the print dialog will appear in the middle at top of their window, if you successfully change that, you might irritate your user base.

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

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kenchan
                  wrote on last edited by
                  #8

                  Thank you for your advice SGaist.

                  You bring up an interesting point because I am not trying to modify the behaviour of the Print Dialog as such, just the Print Preview Dialog.

                  However since you mention it... at the moment I am using the QPrintPreview "out of the box" and it comes with a QPrintDialog which is in this case is a native Mac OSX dialog. This print dialog is not totally modal because you can still click some buttons on its parent and it is repositioned to appear aligned with the bottom of the tool bar of its parent and slightly off to the left.

                  Now that is similar to what I am trying to do with the QPrintPreviewDialog object but can't get it to work on the Mac, hence my question to the forum.

                  These little inconsistencies can be a pain can't they :-).

                  Thanks again

                  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