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. Losing Focus on modal QDialog (Qt5)

Losing Focus on modal QDialog (Qt5)

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 2.4k 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.
  • asdfjklA Offline
    asdfjklA Offline
    asdfjkl
    wrote on last edited by asdfjkl
    #1

    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
    0
    • R Offline
      R Offline
      Rondog
      wrote on last edited by Rondog
      #2

      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
      4
      • asdfjklA Offline
        asdfjklA Offline
        asdfjkl
        wrote on last edited by
        #3

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

        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