Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt - make window top level

Tags:

window

pyqt

i need to make my window top level when i need. Code of creating window:

class Application(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, None, Qt.Tool | Qt.FramelessWindowHint)
        self.setFocusPolicy(Qt.StrongFocus)
        self.setAttribute(Qt.WA_QuitOnClose, True)

And when i need i do:

self.setWindowFlags(Qt.WindowStaysOnTopHint)

But after running this part of code my window hides... I don't know, where is it. But my program doesn't close! Help! How can i make my window top most at need moment?

like image 969
Max Frai Avatar asked May 08 '26 02:05

Max Frai


1 Answers

Calling .show() or .raise() on your window should make it top focus.

And from the doc for setWindowFlags():

Note: This function calls setParent() when changing the flags for a window, causing the widget to be hidden. You must call show() to make the widget visible again..

I just wanted to add for anyone else who finds this question that the Qt doc for C++ is a very good resource even when using PyQt, just make sure you point to the version of the Qt C++ doc that applies to your version of PyQt (The latest PyQt is compiled against 4.4 if that is what you are using).


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!