Results 1 to 8 of 8

Thread: Getting rid of a "stay on top" window behaviour

  1. #1
    Join Date
    Aug 2015
    Posts
    13
    Qt products
    Qt5

    Default Getting rid of a "stay on top" window behaviour

    Hello,
    This should be a simple one, possibly with no miraculous answer as it may depend too much on the window manager, but I have run out of ideas to do this normally. This is a function I call to open new windows. Everything is working perfectly, however windows are all staying on top of the main window, and I would like them not to. parent=None is bad for me as the window closes straight away. Also, I prefer it close when main window closes, so setting the parent is better I think. I would like a reversed Qt.WindowStaysOnTopHint sort of thing. Is there a simple way I missed in the huge list of window attr/flags?

    Qt Code:
    1. def newScopeWindow(self): # TODO stop "always on top" behaviour
    2. window = ScopeFrame(self.radar_contacts, parent=self)
    3. window.setWindowFlags(Qt.Window)
    4. window.setAttribute(Qt.WA_DeleteOnClose)
    5. window.show()
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Getting rid of a "stay on top" window behaviour

    What does ScopeFrame derive from?

    Cheers,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    13
    Qt products
    Qt5

    Default Re: Getting rid of a "stay on top" window behaviour

    Whoops sorry it would have been better to tell straight away. Ui_radarScopeFrame is a Qt designer generated class, as you would have guessed.
    Qt Code:
    1. class ScopeFrame(QWidget, Ui_radarScopeFrame):
    2. def __init__(self, init_contacts, parent=None):
    3. QWidget.__init__(self, parent)
    4. self.setupUi(self)
    5. self.scene = RadarScene(init_contacts, self)
    6. self.scopeView.setScene(self.scene)
    7. ## ... etc. ...
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Getting rid of a "stay on top" window behaviour

    Which template is this based on?
    Dialog?
    Dialogs are traditionally kept on top of their parent.

    Any normal widget created without a parent will also become a top level window.

    Cheers,
    _

  5. #5
    Join Date
    Aug 2015
    Posts
    13
    Qt products
    Qt5

    Default Re: Getting rid of a "stay on top" window behaviour

    Ui_... also is a QWidget. If I set no parent, I only get a working window if I keep a reference to it in main, otherwise it closes straight away. So I would need to build a list of opened windows, detect which one closes (how actually?) to remove the reference. Incidentally, no menu bar in the new windows. All correct?

    And so, there is no way to stop stay-on-top for child windows?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Getting rid of a "stay on top" window behaviour

    Strange, a normal widget should not even show up as a window if it has a parent, it should become part of the parent.
    Your setWindowFlags call probably allows that even when given a parent.

    That "close if not referenced" thing is an artifact introduced by Python. Since it is a garbage collector oriented language, all unreference objects get deleted at some point.

    I am not sure what you mean with "no menu bar", you are deriving from QWidget, menu bar's is a feature of QMainWindow

    Cheers,
    _

  7. #7
    Join Date
    Aug 2015
    Posts
    13
    Qt products
    Qt5

    Default Re: Getting rid of a "stay on top" window behaviour

    Quote Originally Posted by anda_skoa View Post
    Strange, a normal widget should not even show up as a window if it has a parent, it should become part of the parent.
    Your setWindowFlags call probably allows that even when given a parent.
    Yes, it behaves as you say when I do not set it.

    Quote Originally Posted by anda_skoa View Post
    That "close if not referenced" thing is an artifact introduced by Python. Since it is a garbage collector oriented language, all unreference objects get deleted at some point.
    Yes I had guessed that, but of course I cannot do without it.

    Quote Originally Posted by anda_skoa View Post
    I am not sure what you mean with "no menu bar", you are deriving from QWidget, menu bar's is a feature of QMainWindow
    Perhaps a WM thing as well: when parent is main window, the app menu bar is available there as well.

    Thank you very much for all your answers.

  8. #8
    Join Date
    Oct 2014
    Posts
    81
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Qt products
    Qt5
    Platforms
    Windows
    Wiki edits
    7

    Default Re: Getting rid of a "stay on top" window behaviour

    Can't you parent these widgets to some other QObject like the application instance? You can still close them with the main window by connecting their close() slot to a signal that you emit yourself from inside the main window closeEvent() handler. The behaviour is the same.

    As for the on-top behaviour, when the widgets are not parented to the main window anymore, I think setting WA_ShowWithoutActivating on the new widget 'before' showing it, then showing it and then using activateWindow() on the main window (or whatever widget was at the top before the creation of this new widget) to ensure it continues as the top window, is worth a try.

    http://stackoverflow.com/a/1022121/4206247
    Last edited by Kryzon; 14th August 2015 at 19:58.

Similar Threads

  1. Replies: 3
    Last Post: 16th March 2015, 07:31
  2. "Render" Qt dialog window from ".ui" file
    By BitEater in forum Qt Programming
    Replies: 1
    Last Post: 8th July 2011, 14:40
  3. Replies: 3
    Last Post: 17th March 2010, 16:47
  4. Replies: 3
    Last Post: 8th July 2008, 19:37
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.