继承自 Item
FocusScope在创建可重用QML组件时,用于协助进行键盘处理。键盘交互文档中涵盖了所有信息。
本文: https://www.lovejia.win/blog/article/FocusScope.html
参考原文:http://doc.qt.io/qt-5/qml-qtquick-focusscope.html
参考译文:http://blog.csdn.net/vampire_armand/article/details/39156587
功能简述
当构建可重用的QML组件时,FocusScope有助于键盘焦点处理。所有的细节都在键盘焦点文档中。
例
下面示例一个focus文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| import QtQuick 2.1 import "Core"
Rectangle { id: window
width: 800; height: 640 color: "#3E606F"
FocusScope { id: mainView
width: parent.width; height: parent.height focus: true
TabMenu { id: tabMenu y: 160; width: parent.width; height: 160
focus: true activeFocusOnTab: true }
GridMenu { id: gridMenu y: 320; width: parent.width; height: 320 activeFocusOnTab: true }
ListMenu { id: listMenu y: 640; width: parent.width; height: 320 activeFocusOnTab: true }
Rectangle { id: shade anchors.fill: parent color: "black" opacity: 0 }
states: [ State { name: "showTabViews" PropertyChanges { target: tabMenu; y: 160 } PropertyChanges { target: gridMenu; y: 320 } PropertyChanges { target: listMenu; y: 640 } },
State { name: "showGridViews" PropertyChanges { target: tabMenu; y: 0 } PropertyChanges { target: gridMenu; y: 160 } PropertyChanges { target: listMenu; y: 480 } },
State { name: "showListViews" PropertyChanges { target: tabMenu; y: -160 } PropertyChanges { target: gridMenu; y: 0 } PropertyChanges { target: listMenu; y: 320 } } ]
transitions: Transition { NumberAnimation { properties: "y"; duration: 600; easing.type: Easing.OutQuint } } }
Image { source: "Core/images/arrow.png" rotation: 90 anchors.verticalCenter: parent.verticalCenter
MouseArea { anchors.fill: parent; anchors.margins: -10 onClicked: contextMenu.focus = true } }
ContextMenu { id: contextMenu; x: -265; width: 260; height: parent.height }
states: State { name: "contextMenuOpen" when: !mainView.activeFocus PropertyChanges { target: contextMenu; x: 0; open: true } PropertyChanges { target: mainView; x: 130 } PropertyChanges { target: shade; opacity: 0.25 } }
transitions: Transition { NumberAnimation { properties: "x,opacity"; duration: 600; easing.type: Easing.OutQuint } } }
|