按Tab键切换2段文字的焦点,哪段文字的焦点为true,则字体颜色变为红色。
import QtQuick
Window {
width: 640
height: 480
visible: true
title: qsTr("2.2 属性")
Rectangle {
Text {
id: thislabel
text: qsTr("hello world")
font.pixelSize: 20
font.family: "Consolas"
focus: true
color: focus ? "black" : "red"
x: 100; y:100
KeyNavigation.tab: thatlabel
}
Text {
id: thatlabel
text: qsTr("hello world")
font.pixelSize: 20
font.family: "Consolas"
color: focus ? "black" : "red"
x: 100; y:150
KeyNavigation.tab: thislabel
focus: !thislabel.focus
}
}
}