MacOS cannot bring QMainWindow to the front of other apps
-
Hello,
I have a Python Qt app that works well except that when launched from the terminal, the app opens in the background, I have to minimize other apps (e.g. Google Chrome, Outlook) to get to the app (or use CTRL + tab). I have searched wide and large and tried the .raise_() function along with activateWindow() and nothing seems to work. The only time I managed to get the app to display in front is by setting setWindowFlag(Qt.WindowStaysOnTopHint). However, this does not work for my app, because I cannot activate other apps, the Python Qt app remains always on top and all the file browse dialogs in my app get opened in the background.
I am running PySide 6 6.3.0 on MacOS Monterey 12.6.2 and Python 3.9.6.
class MainWindow(QMainWindow): def __init__(self, parent=None, show_dialogs=True, autostart_service=True): super(MainWindow, self).__init__(parent) if __name__ == "__main__": widget = MainWindow() widget.show() widget.activateWindow() widget.raise_()
Thank you for your guidance.
-
Hello,
I have a Python Qt app that works well except that when launched from the terminal, the app opens in the background, I have to minimize other apps (e.g. Google Chrome, Outlook) to get to the app (or use CTRL + tab). I have searched wide and large and tried the .raise_() function along with activateWindow() and nothing seems to work. The only time I managed to get the app to display in front is by setting setWindowFlag(Qt.WindowStaysOnTopHint). However, this does not work for my app, because I cannot activate other apps, the Python Qt app remains always on top and all the file browse dialogs in my app get opened in the background.
I am running PySide 6 6.3.0 on MacOS Monterey 12.6.2 and Python 3.9.6.
class MainWindow(QMainWindow): def __init__(self, parent=None, show_dialogs=True, autostart_service=True): super(MainWindow, self).__init__(parent) if __name__ == "__main__": widget = MainWindow() widget.show() widget.activateWindow() widget.raise_()
Thank you for your guidance.
-
@mazerab said in MacOS cannot bring QMainWindow to the front of other apps:
The command I run in the terminal is:
sudo python main_app.py
It's not a bundle app, so I don't know ...
It's a python script running as root.
I'm not a python expert at all, so I can't help you more. -
What is interesting is that the issue does not exist in Windows and if I run the app executable directly, it is also working
sudo dist_UI/main_app.app/Contents/MacOS/main_app
Why calling the Python script from terminal causes this issue?
@mazerab said in MacOS cannot bring QMainWindow to the front of other apps:
if I run the app executable directly, it is also working
That's the point.
You can use the command "open"
see The macOS open Command