【Qt】-鼠标点击时-Text等控件移动位置
下面,点击鼠标,Text水平移动:
Rectangle {
anchors.fill: parent
color:"red"
Text {
id: text_id
width: 100
height: 20
//anchors.centerIn: parent
text: qsTr("Click me move.")
}
MouseArea {
anchors.fill: parent
onPressed: {
console.log("onPressed");
text_id.x += 10
}
onPositionChanged: {
console.log("onPositionChanged");
}
}
效果如下图所示:


本文介绍如何使用Qt实现鼠标点击时Text控件水平移动的效果。通过MouseArea组件监听鼠标事件,并在事件触发时更新Text控件的位置。
1394

被折叠的 条评论
为什么被折叠?



