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. How to keep the QDialog in the screen without desappearing when it loses the focus
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 3.0k 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.
  • F Offline
    F Offline
    frnklu20
    wrote on last edited by
    #1

    Hi,

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

    JonBJ 1 Reply Last reply
    0
    • F frnklu20

      Hi,

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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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
      2
      • A Offline
        A Offline
        ABCA
        wrote on last edited by
        #3

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

        1 Reply Last reply
        1
        • M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #4

          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
          1
          • F Offline
            F Offline
            frnklu20
            wrote on last edited by
            #5

            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

            JonBJ 1 Reply Last reply
            0
            • F frnklu20

              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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @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
              3
              • F Offline
                F Offline
                frnklu20
                wrote on last edited by
                #7

                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
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved