Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a PyQT4 window jump to the front?

Tags:

I want to make a PyQT4 window(QtGui.QMainWindow) jump to the front when the application received a specified message from another machine. Usually the window is minimized.

I tried the raise_() and show() method but it doesn't work.

like image 956
redice Avatar asked Aug 25 '12 03:08

redice


People also ask

How to center a window in PyQt5?

Sometimes you want to position a window in the middle or center of the computer screen, with PyQt you can do that. To center a Python PyQt window (put it in the center of the screen), we need to do a bit of trickery: we need to get the window properties, center point and move it ourself.

How to open another window PyQt5?

Creating a new window. In Qt any widget without a parent is a window. This means, to show a new window you just need to create a new instance of a widget. This can be any widget type (technically any subclass of QWidget ) including another QMainWindow if you prefer.

What is the use of pyqt4?

PyQt is a Python binding for Qt, which is a set of C++ libraries and development tools providing platform-independent abstractions for graphical user interfaces (GUIs). Qt also provides tools for networking, threads, regular expressions, SQL databases, SVG, OpenGL, XML, and many other powerful features.


2 Answers

This works:

# this will remove minimized status  # and restore window with keeping maximized/normal state window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)  # this will activate the window window.activateWindow() 

Both are required for me on Win7.

setWindowState restores the minimized window and gives focus. But if the window just lost focus and not minimized, it won't give focus.

activateWindow gives focus but doesn't restore the minimized state.

Using both has the desired effect.

like image 159
Avaris Avatar answered Oct 13 '22 01:10

Avaris


This works for me to raise the window but NOT have it on top all the time:

# bring window to top and act like a "normal" window! window.setWindowFlags(window.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)  # set always on top flag, makes window disappear window.show() # makes window reappear, but it's ALWAYS on top window.setWindowFlags(window.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint) # clear always on top flag, makes window disappear window.show() # makes window reappear, acts like normal window now (on top now but can be underneath if you raise another window) 
like image 41
Kevin Newman Avatar answered Oct 13 '22 01:10

Kevin Newman