首页 > 其他 > 详细

QML按键

时间:2019-08-16 09:35:01      阅读:194      评论:0      收藏:0      [点我收藏+]

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
    }
}

效果:

技术分享图片

 

QML按键

原文:https://www.cnblogs.com/judes/p/11361388.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!