QML button

1, common usage

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
ApplicationWindow {
    visible: true
    width: 640
    height: 480
    Rectangle {
        id: rect1
        x:20
        y: 0
        width: 40
        height: 40
        color: "teal"
        scale: focus? 1:0.8
        focus: true
        Keys.onUpPressed: rect1.y - = 1 // button is pressed to change the position
        Keys.onDownPressed: rect1.y += 1
        Keys.onLeftPressed: rect1.x -= 1
        Keys.onRightPressed: rect1.x += 1
        KeyNavigation.tab: rect2 // tab to shift focus to the corresponding id
    }
    Rectangle {
        id: rect2
        x:20
        and 50
        width: 40
        height: 40
        color: "teal"
        scale: focus? 1:0.8
        focus: false
        Keys.onUpPressed: rect2.y -= 1
        Keys.onDownPressed: rect2.y += 1
        Keys.onLeftPressed: rect2.x -= 1
        Keys.onRightPressed: rect2.x += 1
        KeyNavigation.tab: rect1
    }
}
 

effect:

 

Guess you like

Origin www.cnblogs.com/judes/p/11361388.html