Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Losing Focus on modal QDialog (Qt5)

    General and Desktop
    2
    3
    1861
    Loading More Posts
    • 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.
    • asdfjkl
      asdfjkl last edited by asdfjkl

      In my application, I have to often to display a dialog to the user.

      I use

      class MyDialog : public QDialog { }
      

      and to display to the user

      exec()
      

      hence MyDialog is modal. In Microsoft Windows, this works as expected. However in Ubuntu (14.04) and OS X the following happens:

      • If the user clicks (accidently or on purpose) on the maindwindow, the focus of the dialog is lost. The focus is then on the main window (even though the main windows is blocked and does not accept any kind of input). Since the mainwindow gained focus, it is brought ontop of every window, i.e. hides the dialog (you can still bring back the dialog using the ubuntu launcher). Similar behavior occurs on OS X.

      This can be quite confusing for the user, as the mainwindow seems to be blcoked for no apparent reason.

      How can I prevent a modal QDialog from losing focus (actually, not losing focus should be the default behavior according to docu, but as said, this is not the case).

      Did I stumble upon a bug?

      1 Reply Last reply Reply Quote 0
      • R
        Rondog last edited by Rondog

        I suspect that you didn't pass the parent widget to the dialog. You don't show this in your code example so I am only guessing. Without a parent there is no reason for the dialog to stay on-top of anything else (although it might in some cases ?).

        I haven't noticed this problem by the way but I always construct dialog's with a parent (modal or not).

        MyDialog *dialog = new MyDialog(this);
        
        dialog->exec();
        
        1 Reply Last reply Reply Quote 4
        • asdfjkl
          asdfjkl last edited by

          Indeed, that's what I forogt. Thank you so much!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post