QML按鍵


1、普通用法

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//按鍵按下改變位置
        Keys.onDownPressed: rect1.y += 1
        Keys.onLeftPressed: rect1.x -= 1
        Keys.onRightPressed: rect1.x += 1
        KeyNavigation.tab: rect2//tab切換焦點到對應的id
    }
    Rectangle {
        id: rect2
        x:20
        y: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
    }
}
 
        

效果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM