Important: Please read the Qt Code of Conduct -

StackView and kind of focus loss

  • I am trying to create a little application using stackview.

    I made a minimal code that reproduces the problem.
    You have one button "click me" that "opens" a page with an another button that "add text".
    The problem is :
    When I am clicking on a button "click me" and I touch the screen before the end of transition, I can not push the button "add text" even if it is visible. The only thing I can do is to press the back button (with that, the button "click me" appears" but it is not clickable as well...).

    It seems the buttons can be "pressed" (since they change the color : one light grey to one darker grey), but the "clicked" signal is not called... So I think it is about focus but I do not know how to solve this problem... I tried to use one "StackView.Immediate", it "works", but it is not the best solution I can get...

    import QtQuick 2.7
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.0
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        StackView {
            id: stackView;
            anchors.fill: parent;
            initialItem: Item {
                Button {
                    anchors.centerIn: parent;
                    text:"Click me";
                    onClicked: stackView.push(pageComponent);
        Component {
            id: pageComponent;
            Item {
                Text {
                    id: text;
                    anchors{ top:button.bottom; horizontalCenter: parent.horizontalCenter;}
                Button {
                    anchors.centerIn: parent;
                    id: button;
                    text: "add text";
                    onClicked: text.text += "text ";
        onClosing : {
            if(stackView.depth > 1) {
                close.accepted = false;

    I am working both on Android and linux.
    Thanks !

  • I try to know which widget has the focus :
    When it works when I click on the "click me" it is write :

    qml: QQuickItem(0x18b5c10)
    qml: QQuickButton(0x18b77f0)
    qml: QQuickItem(0x1a125d0)

    When it does not work

    it is write :

    qml: QQuickItem(0x18b5c10)
    qml: QQuickButton(0x18b77f0)

    The focus is set to QQuickButton but onClicked does not do anything

Log in to reply