Qt 可聚焦的Qml组件(将我的控件聚焦在选项卡上)
我在qml中创建了一个自定义按钮,我想把重点放在按下“tab”上,我的意思是“如果它在队列顶部,则在按下tab时跳转到它”。默认情况下,qml在按钮本身和一些其他控件上也有此功能,但对于不存在的新组件,我看到了“FocusScope”怎么办控制qml,但没有使用它的文档,我不确定如何实现它,以下是我的控制:Qt 可聚焦的Qml组件(将我的控件聚焦在选项卡上),qt,qml,Qt,Qml,我在qml中创建了一个自定义按钮,我想把重点放在按下“tab”上,我的意思是“如果它在队列顶部,则在按下tab时跳转到它”。默认情况下,qml在按钮本身和一些其他控件上也有此功能,但对于不存在的新组件,我看到了“FocusScope”怎么办控制qml,但没有使用它的文档,我不确定如何实现它,以下是我的控制: import QtQuick 2.4 Item { id: button width: innerText.width + 10 height: 30 pr
import QtQuick 2.4
Item {
id: button
width: innerText.width + 10
height: 30
property alias text: innerText.text;
property alias font: innerText.font;
property color color: "#00171f"
property color hoverColor: "#00395f"
property color pressColor: "#3E65FF"
property int fontSize: 12
property int borderWidth: 0
property int borderRadius: 2
property bool highlighted : true
onEnabledChanged: state = ""
signal clicked
property var background
Rectangle {
id: rectangleButton
anchors.fill: button
radius: borderRadius
color: button.enabled ? button.color : "grey"
border.width: borderWidth
border.color: "black"
Text {
id: innerText
font.pointSize: fontSize
font.family: "B Nazanin"
color: "white"
anchors.centerIn: rectangleButton
}
}
//change the color of the button in differen button states
states: [
State {
name: "Hovering"
PropertyChanges {
target: rectangleButton
color: hoverColor
}
},
State {
name: "Pressed"
PropertyChanges {
target: rectangleButton
color: pressColor
}
}
]
//define transmission for the states
transitions: [
Transition {
from: ""; to: "Hovering"
ColorAnimation { duration: 200 }
},
Transition {
from: "*"; to: "Pressed"
ColorAnimation { duration: 10 }
},
Transition {
from: "*"
to: ""
ColorAnimation { duration: 200 }
}
]
//Mouse area to react on click events
MouseArea {
hoverEnabled: true
anchors.fill: button
onEntered: { button.state='Hovering'}
onExited: { button.state=''}
onClicked: { button.clicked();}
onPressed: { button.state="Pressed" }
onReleased: {
if (containsMouse)
button.state="Hovering";
else
button.state="";
}
}
}
看起来您只是在寻找房产:
Item {
id: button
activeFocusOnTab: true
// ...
}
我也尝试过这个,但没有成功:我用它来添加一个边框,当它聚焦在你的脸上时。