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



  • 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.



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



  • 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() ){
    ...
    }
    @



  • 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.



  • 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.



  • Thank you for your suggestion langi667,

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


  • Lifetime Qt Champion

    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.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.