QML:更改文本字段中的光标颜色 [英] QML: Change cursor color in TextField
本文介绍了QML:更改文本字段中的光标颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 QML TextField
元素中更改光标颜色和可能的宽度?假设我们有以下一个:
How to change cursor color and probably width in QML TextField
element? Let say we have following one:
import QtQuick 2.12
import QtQuick.Controls 2.12
TextField {
id: control
placeholderText: qsTr("Enter description")
background: Rectangle {
implicitWidth: 200
implicitHeight: 40
color: control.enabled ? "transparent" : "#353637"
border.color: control.enabled ? "#21be2b" : "transparent"
}
}
如何使光标颜色为绿色或蓝色或其他?谢谢!
How to make cursor color green or blue or whatever? Thanks!
推荐答案
你必须通过 cursorDelegate
自 TextField
继承自 TextInput
并因此共享该属性.
You have to set Rectangle with the color you want as the cursor through the cursorDelegate
since TextField
inherits from TextInput
and therefore shares that property.
import QtQuick 2.12
import QtQuick.Controls 2.12
TextField {
id: control
placeholderText: qsTr("Enter description")
cursorDelegate: Rectangle {
visible: control.cursorVisible
color: "salmon"
width: control.cursorRectangle.width
}
background: Rectangle {
implicitWidth: 200
implicitHeight: 40
color: control.enabled ? "transparent" : "#353637"
border.color: control.enabled ? "#21be2b" : "transparent"
}
}
这篇关于QML:更改文本字段中的光标颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文