Text:焦点切换文字颜色随之改变

按Tab键切换2段文字的焦点,哪段文字的焦点为true,则字体颜色变为红色。

Text:焦点切换文字颜色随之改变_第1张图片

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

你可能感兴趣的:(QML,qt,qt6,qml,qt,quick,笔记)