2016-12-22 11 views
0

グリッドビューを使用しています。これは左から右にスクロールできます。グリッドビューの各項目をクリックすると、現在のグリッド項目の位置から画面の幅と画面の高さまでのアニメーションで新しい画面が開きます。グリッドビューを右にスクロールした後に2番目の列の要素をクリックすると、グリッド項目の位置が間違っています。これを修正する方法はありますか?または、グリッドビューが右端までスクロールされているかどうかを確認する方法はありますか?グリッドビューが最後までスクロールされているかどうかを確認する方法

は、以下の私のコードを入れています:あなたが探しているものを

 GridView { 
         id: featuresGrid 
         snapMode: ListView.SnapToItem 
         clip:true 
         x: 135 
         y: 122 
         width:1650 
         height:485 
         cellWidth: 825 
         cellHeight: 160 
         flow: GridView.FlowTopToBottom 
         model:favouriteapp 
         delegate:featureGridTile 
         focus: false 
        } 

    ListModel { 
      id:favouriteapp 
      ListElement { 
       featureName: "media & radio" 
      } 
      ListElement { 
       featureName: "phone" 
      } 
      ListElement { 
       featureName: "climate" 
      } 
      ListElement { 
       featureName: "navigation" 
      } 
      ListElement { 
       featureName: "ambient lighting" 
      } 
      ListElement { 
       featureName: "settings" 
      } 

      ListElement { 
       featureName: "camera" 
      } 

      ListElement { 
       featureName: "dynamic-i" 
      } 

      ListElement { 
       featureName: "bluetooth" 
      } 


     } 

    Component { 
       id: featureGridTile 
       Item { 
        id:grid_view_rect 
        width:featuresGrid.cellWidth 
        height:featuresGrid.cellHeight 
        Text{ 
         anchors.fill: parent 
         text : featureName 
         opacity: 1 
        } 

        MouseArea{ 
         anchors.fill: parent 

         onClicked: { 
          featuresGrid.currentIndex = index 
          //Goes to the next screen with the current clicked grid item X and Y position 

         } 
        } 
       } 

      } 
+0

あなたはMCVE基準をfullfills例を提供することはできますか? http://stackoverflow.com/help/mcve未知の 'downscaleFactors'、' utilObj'または 'featureGridTiles'への参照はありません。私はあなたのコードを実行し、問題を見て、それを修正したいと思います。しかし、私は、例をまったく実行させるために絶え間なく仕事をしたくありません。 – derM

+0

私はコードを更新しました。 –

+0

よろしくお願いします。それでも私が要素をクリックすると、何が起こるはずなのでしょうか?あなたがクリックしたタイルが拡大しているように、新しいものが現れるはずです。そしてあなたは、始めるべき地位を見つけることができませんか? – derM

答えて

0

mapFromItemmapToItem関数です: http://doc.qt.io/qt-5/qml-qtquick-item.html#mapFromItem-method-1

Item { 
    id: rootItem 
    anchors.fill: parent 


    Rectangle { 
     id: myRect 
     color: 'red' 
     width: 50 
     height: 50 
     // the + 0 * featuresGrid.contentX will force the binding to reevaluate when draged. Maybe you don't want that. Comment it out and try 
     x: featuresGrid.currentItem.mapToItem(rootItem, 0, 0).x + 0 * featuresGrid.contentX 
     y: featuresGrid.currentItem.mapToItem(rootItem, 0, 0).y + 0 * featuresGrid.contentY 
     z: 1 
    } 


    GridView { 
     id: featuresGrid 
     snapMode: ListView.SnapToItem 
     clip:true 
     x: 135 
     y: 122 
     width:1650 
     height:485 
     cellWidth: 825 
     cellHeight: 160 
     flow: GridView.FlowTopToBottom 
     model:favouriteapp 
     delegate:featureGridTile 
     focus: false 
    } 

    ListModel { 
     id:favouriteapp 
     ListElement { 
      featureName: "media & radio" 
      soureIcon:"file:graphics/Icons/MediaIcon.png" 
      feature:"Media" 
     } 
     ListElement { 
      featureName: "phone" 
      soureIcon:"file:graphics/Icons/Phoneicon.png" 
      feature:"Phone" 
     } 
     ListElement { 
      featureName: "climate" 
      soureIcon:"file:graphics/Icons/ClimateIcon.png" 
      feature:"Climate" 
     } 
     ListElement { 
      featureName: "navigation" 
      soureIcon:"file:graphics/Icons/NavIcon.png" 
      feature:"Navigation" 
     } 
     ListElement { 
      featureName: "ambient lighting" 
      soureIcon:"file:graphics/Icons/ALIcon.png" 
      feature:"AL" 
     } 
     ListElement { 
      featureName: "settings" 
      soureIcon:"file:graphics/Icons/SettingsIcon.png" 
      feature:"Settings" 
     } 

     ListElement { 
      featureName: "camera" 
      soureIcon:"file:graphics/Icons/CamIcon.png" 
      feature:"Camera" 
     } 

     ListElement { 
      featureName: "dynamic-i" 
      soureIcon:"file:graphics/Icons/dynamicIcon.png" 
      feature:"Dynamic_I" 
     } 

     ListElement { 
      featureName: "bluetooth" 
      soureIcon:"file:graphics/Icons/Icon Bluetooth.png" 
      feature:"Bluetooth" 
     } 


    } 
} 

Component { 
    id: featureGridTile 
    Item { 
     id:grid_view_rect 
     width:featuresGrid.cellWidth 
     height:featuresGrid.cellHeight 
     Rectangle{ 
      anchors.fill: parent 
      color: "white" 
      opacity: 1 
      border.color: 'black' 
     } 

     Text{ 
      anchors.fill: parent 
      text : featureName 
      opacity: 1 
     } 

     MouseArea{ 
      anchors.fill: parent 

      onClicked: { 
       featuresGrid.currentIndex = index 
       //Goes to the next screen with the current clicked grid item X and Y position 
      } 
     } 
    } 

} 
+0

ありがとうございます。これは探しているものです。 –

+0

私はあなたを助けることができてうれしいです:-) – derM

関連する問題