我如何在QML TextField中更改placeholderText颜色

时间:2019-06-25 11:55:14

标签: qt qml textfield

我尝试使用TextField Styled,但对占位符文本没有影响,如何更改placeholderText的颜色

1 个答案:

答案 0 :(得分:3)

TextField具有专用于颜色的属性placeholderTextColor

使用Qt Quick Controls 2(至少需要Qt 5.12):

import QtQuick.Controls 2.5
TextField {
    anchors.fill: parent
    placeholderText: "Here is a place holder"
    placeholderTextColor: "red"
}

使用Qt快速控件1:

import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
TextField {
      anchors.fill: parent
      style: TextFieldStyle {
          placeholderTextColor: "red"
      }
      placeholderText: "Here is a place holder"
}