Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved How to keep the QDialog in the screen without desappearing when it loses the focus

    General and Desktop
    4
    7
    1669
    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.
    • F
      frnklu20 last edited by

      Hi,

      How can i keep a modeless QDialog on the screen even when it loses the focus?

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @frnklu20 last edited by

        @frnklu20
        Show your code. It should stay on the screen. Unless maybe your dialog is getting deleted/going out of scope in your code.

        1 Reply Last reply Reply Quote 2
        • A
          ABCA last edited by

          Have you tried Implementing QDialog::show() in FocusOutEvent?

          1 Reply Last reply Reply Quote 1
          • M
            mpergand last edited by mpergand

            I suppose by desappearing you mean that you would like to prevent the dialog to be obscured by another window.
            I think the Qt::Tool windowflag could be of interest:

            Qt::Tool
            Popup | Dialog
            Indicates that the widget is a tool window. A tool window is often a small window with a smaller than usual title bar and decoration, 
            typically used for collections of tool buttons. If there is a parent, the tool window will always be kept on top of it. If there isn't a parent, 
            you may consider using Qt::WindowStaysOnTopHint as well. If the window system supports it, 
            a tool window can be decorated with a somewhat lighter frame. 
            It can also be combined with Qt::FramelessWindowHint. On OS X, tool windows correspond to the Floating class of windows. 
            This means that the window lives on a level above normal windows; it impossible to put a normal window on top of it. 
            By default, tool windows will disappear when the application is inactive. 
            This can be controlled by the Qt::WA_MacAlwaysShowToolWindow attribute.
            

            Work well on Mac for me, not sure for the other OS.

            1 Reply Last reply Reply Quote 1
            • F
              frnklu20 last edited by

              Hi,

              That's it! My program is composed of a mainwindow and when i press a button it opens a dialog, but i don't want that the dialog get obscured by the mainwindow when it loses focus.
              It's just to keep in the same position.

              0_1568290418081_e1a3f235-e9a4-43a2-86e8-beb7798833b5-image.png

              When i click on the plus button this dialog, that have buttons appears, but even when it loses focus i want it to stay there and not get behind of the mainwindow.

              itemDialog::itemDialog(QWidget *parent) :
                  QDialog(parent)
              { ......
                       Qt::WindowFlags flags = 0;      
                       flags = Qt::Tool;
              
              }
              

              i tryed this, but i don't know if i'm implementing in the right way

              JonB 1 Reply Last reply Reply Quote 0
              • JonB
                JonB @frnklu20 last edited by JonB

                @frnklu20
                That's not "disappearing from the screen when losing focus", it's just another window coming on top! Had no idea you could mean that!

                No, your code won't do anything, it simply sets an (unused) local variable. From where you are now replace by:

                setWindowFlags(windowFlags()  | Qt::Tool);
                
                1 Reply Last reply Reply Quote 3
                • F
                  frnklu20 last edited by

                  hi,

                  i found another solution, instead of creating another class and implementing it, i created a QDialog inside of the mainwindow
                  and used the mainwindow as a parent.

                  Thanks guys, you're awesome

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