QML MouseArea中的hoverEnabled屬性影響onEntered, onExited

        學習過程,記錄一下。html

        這段時間學習Quick2在本身定義一個按鈕時想作一個效果,鼠標懸停在按鈕上時按鈕背景顯示一種顏色,鼠標離開時回覆原樣。學習

        剛開始是代碼是這樣的:ui

Rectangle{
            color:"green"
            width: 28
            height: 28

            MouseArea{
                anchors.fill:parent

                onEntered: {
                    parent.color="red";
                }

                onExited: {
                    parent.color="green";
                }
             }
        }

        onEntered事件死活不執行,後來看了幫助文檔這樣寫
spa

        hoverEnabled : boolcode

        This property affects the containsMouse property and the onEntered, onExited and onPositionChanged signals.htm

     默認hoverEnabled屬性是false,結果代碼加上hoverEnabled:true,結果就出來了。事件

Rectangle{
            color:"green"
            width: 28
            height: 28

            MouseArea{
                anchors.fill:parent
                hoverEnabled: true;

                onEntered: {
                    parent.color="red";
                }

                onExited: {
                    parent.color="green";
                }
             }
        }

        英語是死穴,學起來也費勁,加油!!
文檔

相關文章
相關標籤/搜索