3

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?

1 Answer 1

7

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).

1
  • 1
    window.raise_() does not work for me on Linux and PyQt 4.8.3, Is it a bug?
    – saeedgnu
    Mar 27, 2011 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.