2

QML に問題があります。TextInputアクションに基づいて を編集し、focus属性をに設定したいと思いますtrue。が にある場合に機能しますが、 にTextInputはありRectangleませんScrollView。次に例を示します。

Item {
    id: main
    width: 640
    height: 480

    ScrollView{
        id: scrollView
        height: parent.height/2
        width: parent.width

        Rectangle{
            border.color: "black"
            border.width: 1
            anchors.centerIn: parent
            height: 25
            width: 200
            TextInput{
                id: ti1
                anchors.fill: parent
                verticalAlignment: TextInput.AlignVCenter
                horizontalAlignment: TextInput.AlignHCenter
            }
        }

    }

    Rectangle{
        y: height
        height: parent.height/2
        width: parent.width

        Rectangle{
            border.color: "black"
            border.width: 1
            anchors.centerIn: parent
            height: 25
            width: 200
            TextInput{
                id: ti2
                anchors.fill: parent
                verticalAlignment: TextInput.AlignVCenter
                horizontalAlignment: TextInput.AlignHCenter
            }
        }
    }

    MouseArea{
        anchors.fill: parent
        onClicked: {
            if (mouseY < parent.height/2){
                ti2.focus = false
                ti1.focus = true
            }else{
                ti1.focus = false
                ti2.focus = true
            }
        }
    }

}

ウィンドウの下半分をクリックすると、TextInputti2 が編集可能になります。しかし、上半分をクリックすると、ti1 はありません。

誰にもアイデアはありますか?動作は と同じTextEditです。

ありがとう。

4

1 に答える 1

3

「ScrollView の直接の子にできるのは 1 つの項目だけであり、子はスクロール ビューを埋めるために暗黙的に固定されている」ためだと思い ます。.

から: http://doc.qt.io/qt-5/qml-qtquick-controls-scrollview.html

コンポーネントのツリーが ScrollView で利用できない可能性があります。

ただし、次を使用する場合:

ti1.forceActiveFocus();

それ以外の:

ti1.focus = true

できます。

于 2015-05-29T09:16:37.757 に答える