jeudi 12 avril 2018

Qt: checkbox single click not working

I'm playing around with QtQuick in Qt 5.9 and I encountered strange issue. When I created two Tumblers and a CheckBox in QML everything was working fine.

But when I created event handler for a id: secondTumbler which manipulates testCheckBox.checked status the CheckBox started to act in a strange way.

When I launch the app and firstly scroll around any tumbler and then click the CheckBox it will not check. The second click will eventual check it but that is a strange behavior.

The only thing I wrote is the below code in the main.qml:

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Tumbler {
        id: firstTumbler
        model: 10
        anchors.left: parent.left
    }

    Tumbler {
        id: secondTumbler
        model: 10
        anchors.right: parent.right

        onCurrentIndexChanged: {
                testCheckBox.checked = false
        }
    }

    CheckBox {
        id: testCheckBox
        anchors.left: firstTumbler.right

        onCheckedChanged: {
            if(testCheckBox.checked == true)
            {
                secondTumbler.currentIndex = firstTumbler.currentIndex
            }
        }
    }
}

What am I missing?




Aucun commentaire:

Enregistrer un commentaire