QMLx學習06Button 1、Button 1.1 狀態改變(checkable) 1.2 排斥性(autoExclusive) 1.3 重復觸發(autoRepeat)、第一次觸發延時時間(autoRepeatDelay)、相互之間觸發的時間間隔(autoRepeatInterval) 1.4 鼠標按下(onDownChanged) 1.5 改變按鈕背景顏色和邊框顏色(background: Rectangle、border.color) 2、總結
1、Button
1.1 狀態改變(checkable)
Button { id: btnwidth: 50 height: 50 checkable: false onCheckableChanged: { console. log ( "changed" , checkable) } onClicked: { btn. checkable = ! btn. checkable }
1.2 排斥性(autoExclusive)
Button { id: btnwidth: 50 height: 50 autoExclusive: true checkable: true
} Button { id: btn1width: 50 height: 50 x: 60 autoExclusive: true checkable: true
} Button { id: btn2width: 50 height: 50 x: 120 autoExclusive: true checkable: true
}
1.3 重復觸發(autoRepeat)、第一次觸發延時時間(autoRepeatDelay)、相互之間觸發的時間間隔(autoRepeatInterval)
Button{ id: btnwidth: 50 height: 50 autoRepeat: true autoRepeatDelay: 2000 autoRepeatInterval: 1000 onClicked: { console. log ( "clicked" ) } onPressed: { console. log ( "pressed" ) } onReleased: { console. log ( "released" ) ; }
}
1.4 鼠標按下(onDownChanged)
Button{ id: btnwidth: 50 height: 50 autoRepeat: true autoRepeatDelay: 2000 autoRepeatInterval: 1000 checkable: true onDownChanged: { console. log ( "down:" , down, "pressed" , pressed) } }
1.5 改變按鈕背景顏色和邊框顏色(background: Rectangle、border.color)
Button{ id: btnwidth: 50 height: 50 autoRepeat: true background: Rectangle{ anchors. fill: btncolor: { if ( btn. pressed) { return "green" } else { return "blue" } } border. width: 5 border. color: { if ( btn. pressed) { return "red" } else { return "black" } } }
}
2、總結
以上就是Button的一些基礎知識了,瀏覽過程中,如若發現錯誤,歡迎大家指正,有問題的歡迎評論區留言或者私信。最后,如果大家覺得有所幫助,可以點一下贊,謝謝大家!祝大家天天開心,順遂無虞!