标题:FocusScope 的 activeFocus 条件没有生效
作者:bphanzhu
日期:2012-08-29 23:33
内容:
使用 QML 写的一个 TextEntry,希望在获得焦点时,边框的宽度和颜色发生变化,但是在测试的时候发现TextEntry获取到焦点之后,边框和背景均没有发生变化,请问是否 QML 写的有误?或者系统、QT的什么配置可能导致这个问题-.-
import QtQuick 1.1
FocusScope {
id: focusScope
width: 200;
height: 36
property alias text: textInput.text
property alias echoMode: textInput.echoMode
property alias validator: textInput.validator
Rectangle {
id: container
width: parent.width
height: parent.height
anchors.fill: parent
color: parent.activeFocus ? "#ffffff" : "#e6e1e1"
border.width: parent.activeFocus ? 2 : 1
border.color: parent.activeFocus ? "blue": "gray"
radius: 6
}
TextInput {
id: textInput
font.pointSize: 12
anchors.rightMargin: 10
anchors.leftMargin: 10
anchors.bottomMargin: parent.height / 6
anchors.topMargin: parent.height / 6
anchors.fill: parent
focus: true
selectByMouse: true
..
#1 [dgglx 11-23 16:42]
我把你的代码运行了一下,可以啊!效果是:单击输入框的时候,边框颜色变成蓝色,并加粗了啊!是要这个效果吗??
#2 [dgglx 11-23 16:42]
我是在windows下的Qt creator 2.4.1
#3 [dgglx 11-23 16:56]
附图:
鼠标点击之前
点击之后