PDA

View Full Version : Getting rid of a "stay on top" window behaviour



mickybadia
13th August 2015, 12:20
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?



def newScopeWindow(self): # TODO stop "always on top" behaviour
window = ScopeFrame(self.radar_contacts, parent=self)
window.setWindowFlags(Qt.Window)
window.setAttribute(Qt.WA_DeleteOnClose)
window.show()

anda_skoa
13th August 2015, 12:38
What does ScopeFrame derive from?

Cheers,
_

mickybadia
13th August 2015, 14:00
Whoops sorry it would have been better to tell straight away. Ui_radarScopeFrame is a Qt designer generated class, as you would have guessed.


class ScopeFrame(QWidget, Ui_radarScopeFrame):
def __init__(self, init_contacts, parent=None):
QWidget.__init__(self, parent)
self.setupUi(self)
self.scene = RadarScene(init_contacts, self)
self.scopeView.setScene(self.scene)
## ... etc. ...

anda_skoa
13th August 2015, 15:07
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,
_

mickybadia
13th August 2015, 16:52
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?

anda_skoa
13th August 2015, 18:36
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,
_

mickybadia
13th August 2015, 18:54
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.


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.


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.

Kryzon
14th August 2015, 19:07
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