2017-03-17 22 views
0

Qt/QMLプログラミングが初めてで、次の例がモバイルデバイスで正しく動作するようにしようとしています。 「右にスワイプ」してから削除ボタンをタップすると、「リストビュー項目」は削除されません。デスクトップ上では正常に動作しますが、モバイルデバイスでは正常に動作しません。誰も私の問題を助けてくれる?Qt/QML SwipeDelegateがモバイルデバイス(Android、iOS)で正しく動作しない

import QtQuick 2.7 
import QtQuick.Controls 2.0 

ApplicationWindow { 
    id: appWindow 
    visible: true 

    ListView { 
     id: listView 
     anchors.fill: parent 
     model: ListModel { 
      ListElement { name: "Swipe Delegate - Test 1" } 
      ListElement { name: "Swipe Delegate - Test 2" } 
      ListElement { name: "Swipe Delegate - Test 3" } 
      ListElement { name: "Swipe Delegate - Test 4" } 
     } 
     delegate: SwipeDelegate { 
      id: swipeDelegate 
      text: model.name 
      width: parent.width 

      ListView.onRemove: SequentialAnimation { 
       PropertyAction { 
        target: swipeDelegate 
        property: "ListView.delayRemove" 
        value: true 
       } 
       NumberAnimation { 
        target: swipeDelegate 
        property: "height" 
        to: 0 
        easing.type: Easing.InOutQuad 
       } 
       PropertyAction { 
        target: swipeDelegate; 
        property: "ListView.delayRemove"; 
        value: false 
       } 
      } 

      swipe.right: Label { 
       id: deleteLabel 
       text: qsTr("Delete") 
       color: "white" 
       verticalAlignment: Label.AlignVCenter 
       padding: 12 
       height: parent.height 
       anchors.right: parent.right 

       SwipeDelegate.onClicked: listView.model.remove(index) 

       background: Rectangle { 
        color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato" 
       } 
      } 
     } 
    } 
} 

答えて

0

onClickedイベントを使用してMouseAreaをRectangle内に追加できます。ここに例があります:

background: Rectangle { 
       color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato" 
       MouseArea { 
        anchors.fill: parent 
        onClicked: listView.model.remove(index) 
       } 
} 
+0

ありがとうございます、それは完璧に正常に動作します –

関連する問題