Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Focus and handling hide command on MacOS Catalina
Forum Updated to NodeBB v4.3 + New Features

QML Focus and handling hide command on MacOS Catalina

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 238 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.
  • G Offline
    G Offline
    GGlowack
    wrote on 28 Feb 2023, 16:09 last edited by GGlowack 3 Jun 2023, 13:34
    #1

    Hello,

    I am having a problem working out a solution to the following problem.
    Here is a simplified version of the app showing hiding/showing mechanism:

    (QT 6.2.4)

    import QtQuick
    import QtQuick.Controls
    import Qt.labs.platform
    
    ApplicationWindow {
        id: appWindow
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
      
       function showWindow() {
            show()
            raise()
            requestActivate()
        }
    
        function hideWindow() {
           hide()
        }
    
        SystemTrayIcon {
            visible: true
            iconSource: "qrc:/images/tray-icon.png"
    
            menu: Menu {
                id: trayMenu
                MenuItem {
                    text: qsTr("Show")
                    onTriggered: {
                        appWindow.showWindow()
                    }
                }
                MenuItem {
                    text: qsTr("Hide")
                    onTriggered: {
                        appWindow.hideWindow()
                    }
                }
            }
            
            onActivated: function(reason) {
                /// bring appWindow to the front on mouse right click
                if (reason === SystemTrayIcon.Context || reason === SystemTrayIcon.DoubleClick) 
                {
                        appWindow.showWindow() 
                }
            }
        }
    }
    

    When I am doing hide -> show using tray icon menu options (left click on the tray icon to get the menu dropdown) window is correctly hiding and showing itself and also correctly handling OS hide event (Ctrl+H).
    It works differently when instead of hiding it using hide from system tray I submit Ctrl+H and then click the right mouse button on the tray icon (invoking appWindow.showWindow()). After that window is brought to the front and shown but next Ctrl+H will not hide it anymore.

    Adding modality: Qt.ApplicationModal to the appWindow solves this problem since now it will be the only window that handles keystrokes and inputs but this will disable access to SystemTrayIcon when the window is not hidden.

    From some testing, this seems to be a Catalina-specific bug because it works fine in the latter OS versions.
    I am looking at least for some workaround to this problem.

    1 Reply Last reply
    0

    1/1

    28 Feb 2023, 16:09

    • Login

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