2015-05-13 115 views
0

我有這樣的代碼:的GridView和鼠標區域內衝突

import QtQuick 2.0 
import QtQuick.Window 2.0 

Window { 
    visible: true 
    width: 500 
    height: 500 

    GridView { 
     id: grid 
     anchors.fill: parent 
     cellWidth: 30 
     cellHeight: 30 
     model: 120 
     delegate: Rectangle { 
      width: grid.cellWidth 
      height: grid.cellHeight 
      color: "grey" 
     } 

     MouseArea { 
      anchors.fill: parent 
      onPressed: console.info(">> PRESSED triggered") 
      onMouseXChanged: console.info(">> " + mouseX) 
      onReleased: console.info(">> RELEASED triggered") 
      preventStealing: true 
      propagateComposedEvents: true 
     } 
    } 
} 

當我握着鼠標按鈕並在MouseArea觸發嚴格移動它沿X軸,所有的信號。但是,當鼠標也沿着Y軸向上或向下移動時,onMouseXChangedonReleased信號不會觸發。看來GridView攔截了MouseArea的信號,從MouseArea中竊取了他們。我如何讓他們一起工作:GridViewMouseArea裏面?

回答

0

在您的MouseArea中設置preventStealingtrue

該屬性保存鼠標事件是否可能從此MouseArea中被盜。

如果鼠標區域放置在篩選子鼠標事件(例如Flickable)的項目內,則如果父項目識別出手勢,則鼠標事件可能從MouseArea中被盜取。輕彈手勢。如果preventStealing設置爲true,則沒有項目會盜取鼠標事件。

+0

是的,這工作,但電網現在不是可滑動的 – Constantine

+0

你沒有提到,作爲你的問題的要求。 – Mitch

+0

好吧,我的錯。我編輯它。 – Constantine