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. Can't show() QWindow when it was hidden with cmd + h on MacOS
Forum Updated to NodeBB v4.3 + New Features

Can't show() QWindow when it was hidden with cmd + h on MacOS

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 266 Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Katos
    wrote on last edited by Katos
    #1

    I have an issue that I cannot raise my app Window when it got hidden with MacOS shortcut. It work correctly in all other cases.

    In my app i have 1 main qWindow called QWindow* mMainWindow; and following code added to tray button

    mMenu->addAction(createAction("Show", [=] {
        if (mMainWindow) {
            mMainWindow->show();
            mMainWindow->raise();
            mMainWindow->requestActivate();
        }
    

    When I just use qt mMainWindow->hide() and then raise it back, mMainWindow works fine. Method mMainWindow->isActive() return correct true state when app is active and false when it is hidden.

    But when I hide app using build-in in mac "cmd + h", mMainWindow->isActive() return true regardless if app app is hidden or not. Calling my action item does nothing, mMainWindow stay all the time hidden.

    Is there any solution to fix this issue? I have seen people recommend using QWidget instead of QWindow and calling widget->activateWindow() but it is not solution i can use in my case.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Which version of Qt are you using ?
      On which version of macOS ?
      Can you provide a minimal compilable example that shows that behaviour ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Katos
        wrote on last edited by Katos
        #3

        Which version of Qt are you using ? 5.15.0
        On which version of macOS ? Mojave
        Can you provide a minimal compilable example that shows that behaviour ?

        Here is quick example of the problem (mine tray is written in cpp, but i can see that problem also appear when using qml one).

        Click Hide then Show and it work fine.
        Use "cmd + h" then Show and it doesnt.

        import QtQuick 2.15
        import QtQuick.Window 2.15
        import Qt.labs.platform 1.1
        
        Window {
            id: window
            visible: true
            width: 640
            height: 480
        
            SystemTrayIcon {
                visible: true
        
                menu: Menu {
                    MenuItem {
                        text: qsTr("Show")
                        onTriggered: {window.show(); window.raise(); }
                    }
                    MenuItem {
                        text: qsTr("Hide")
                        onTriggered: window.hide()
                    }
                }
            }
        
        }
        

        After writing this example i have realised that if you call Hide after Window was hidden with Mac shortcut, Show will work. (didn't realise sooner because my app has no Hide button)
        So looks like i will just add to my show button extra hide() call as a work-around to this bug and my code will looks like this.

            mMenu->addAction(createAction("Show", [=] {
                if (mMainWindow) {
                    mMainWindow->hide();
                    mMainWindow->show();
                    mMainWindow->raise();
                    mMainWindow->requestActivate();
                }
            }));
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I currently do not know whether the CMD+H action provides any feedback to the application. Your workaround was what came to mind. Glad it is working.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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