2013-10-23 9 views
7

Po aktywowaniu celu upuszczania jest ono nadal aktywne, nawet gdy kursor przesunie się do innego celu upuszczania, który znajduje się nad pierwotnym celem upuszczenia.Jak prawidłowo zaimplementować zachodzące na siebie miejsca upuszczania?

Oto demo QML: Spróbuj upuścić plik na szare i niebieskie obszary. Niebieski nigdy się nie aktywuje.

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" 
    } 
} 

Jak mogę zaimplementować upuszczanie na oba prostokąty szary i niebieski?

+0

czy to rozwiązano? – ustulation

Odpowiedz

2

Nie możesz tego zrobić w ten sposób, ponieważ zaraz po wejściu do szarej strefy, otrzymasz fokus i (nawet jeśli umieścisz niebieską strefę) niebieski droparea nigdy nie otrzyma zdarzenia.

Musisz uczynić niebieską strefę dzieckiem szarej droparei, ale teraz pojawia się nowy problem: onDrop na niebieskiej strefie, szara strefa również dostaje wydarzenie, więc musisz zablokować wydarzenie, jeśli było kropla na niebiesko (to jest użycie własności 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" 
    } 
} 
Powiązane problemy