7

ドロップ ターゲットがアクティブ化されると、カーソルが元のドロップ ターゲットの上にある別のドロップ ターゲットに移動してもアクティブなままです。

QML のデモは次のとおりです。灰色と青色の領域にファイルをドロップしてみてください。青いものはアクティブになりません。

import QtQuick 2.1

Rectangle {
    color: "grey"
    width: 300
    height: 300

    DropArea {
        anchors.fill: parent
        onDropped: status.text = "Dropped on Grey";
    }

    Rectangle {
        color: "blue"
        anchors.fill: parent
        anchors.margins: 80

        DropArea {
            anchors.fill: parent
            # Never active!
            onDropped: status.text = "Dropped on Blue" 
        }
    }

    Text {
        x: 10
        y: 10
        id: status
        text: "Nothing dropped"
    }
}

グレーとブルーの両方の長方形へのドロップを実装するにはどうすればよいですか?

4

1 に答える 1

3

灰色のゾーンに入るとすぐにフォーカスが得られ、(青いゾーンにカーソルを合わせても) 青いドロップエリアがイベントを受信しないため、そのようにすることはできません。

ブルー ゾーンをグレーの droparea の子にする必要がありますが、新しい問題があります。ブルー ゾーンの onDrop では、グレー ゾーンもイベントを取得するため、ブルー ゾーンにドロップされた場合はイベントをブロックする必要があります (これは blueDrop プロパティの使用です) :

Rectangle {
    color: "grey"
    width: 300
    height: 300

    DropArea {
        id: greyDrop;
        property bool blueDrop: false;
        anchors.fill: parent
        onDropped: blueDrop ? blueDrop = false : status.text = "Dropped on Grey";

        Rectangle {
            color: "blue"
            anchors.fill: parent
            anchors.margins: 80

            DropArea {
                anchors.fill: parent
                onDropped: { status.text = "Dropped on Blue"; greyDrop.blueDrop = true; }
            }

        }
    }
    Text {
        id: status
        text: "Nothing dropped"
    }
}
于 2014-02-13T13:34:39.780 に答える