Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. MacOS cannot bring QMainWindow to the front of other apps

MacOS cannot bring QMainWindow to the front of other apps

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 550 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mazerab
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • M mazerab

      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.

      M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      @mazerab said in MacOS cannot bring QMainWindow to the front of other apps:

      I have a Python Qt app that works well except that when launched from the terminal

      Hi,

      What command do you use in the terminal ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mazerab
        wrote on last edited by mazerab
        #3

        The command I run in the terminal is:

        sudo python main_app.py
        
        M 1 Reply Last reply
        0
        • M mazerab

          The command I run in the terminal is:

          sudo python main_app.py
          
          M Offline
          M Offline
          mpergand
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mazerab
            wrote on last edited by
            #5

            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?

            M 1 Reply Last reply
            0
            • M mazerab

              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?

              M Offline
              M Offline
              mpergand
              wrote on last edited by
              #6

              @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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved