2016-12-22 5 views
0

Я использую вид сетки, который можно прокручивать слева направо. Когда вы нажимаете на каждый элемент в виде сетки, новый экран запускается с анимацией из текущего положения позиции сетки до ширины экрана и высоты экрана. Когда вы нажимаете на элементы второго столбца после прокрутки сетки вправо, позиция элемента сетки становится неправильной. Есть ли способ исправить это? Или есть ли способ проверить, прокручивается ли сетка в крайнем правом углу?Как узнать, прокручивается ли сетка до конца

кладу мой код ниже:

 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? http://stackoverflow.com/help/mcve Нет ссылок на неизвестные 'downscaleFactors',' utilObj' или 'featureGridTiles'. Я хочу запустить ваш код, увидеть вашу проблему и предоставить исправление, если можно. Но я не хочу неустанно работать, чтобы запустить пример. – derM

+0

Я обновил код. –

+0

ОК, я запустил его сейчас. Тем не менее, я не понимаю, что должно произойти, как только я нажал на элемент. Должна появиться новая вещь, как плитка, на которую вы нажимали, расширяется? И вы не можете найти позицию сперва, чтобы начать? – derM

ответ

0

Что вы ищете являются mapFromItem и mapToItem функции: 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

Смежные вопросы