Quit Application if another Window hides it (X11)



  • I have a small qml application which displays an animation on the screen if there is an inactivity by the user for some time.
    This application waits for "onClick" (we have a touchscreen only) and exits.
    But if another application is started, the application screen is not visible anymore and it never receives any mouseclick. In this case, it should also exit.

    But I don't know how how. I have tried to use some onXXX functions. The problem starts already that I cannot find a documentation which "onXXX" functions are already available.

    The application:

    import QtQuick 2.0

    Item {
    width: 1024
    height: 600
    MouseArea {
    onClicked: {
    console.log("onClicked");
    Qt.quit();
    }
    anchors.fill: parent
    }
    }

    AnimatedSprite {
    id: sprite
    width: 1024
    height: 600
    anchors.centerIn: parent
    source: "content/awibuben_spritesheet.png"
    frameCount: 5
    frameSync: true
    frameWidth: 1024
    frameHeight: 600
    }
    }

    I have also tried to use "Window" where I can receive "onActiveChanged", but the event comes only at the beginning but not when another fullscreen window is placed above this one.
    I use X11 with matchbox display manager.

    Any solutions?

    Not so nice, but it would also help to keep the application always in the foreground.



  • I have found a solution:

    The app exits, if the touch screen is pressed or if another application is started. Just as I wanted.

    import QtQuick 2.2
    import QtQuick.Window 2.1

    Item {

    Window { id: mainwindow
    width: 1024
    height: 600
    visible: true
    visibility: Window.Maximized

    modality: Qt.ApplicationModal
    // if it should stay on top:   flags: Qt.SplashScreen
    
    
    MouseArea {
        onClicked: Qt.quit();
        anchors.fill: parent
    }
    
    onActiveChanged: {
         console.log("onActiveChanged");
         if (active == 0) Qt.quit();
    }
    

    AnimatedSprite {
    id: sprite
    width: 1024
    height: 600
    anchors.centerIn: parent
    source: "content/awibuben_spritesheet.png"
    frameCount: 5
    frameSync: true
    frameWidth: 1024
    frameHeight: 600
    }
    }
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.