[Interest] QML: PlaceholderText on ComboBox (Controls 2)

Carel Combrink carel.combrink at gmail.com
Sun Sep 1 21:21:53 CEST 2019


I have a ComboBox (QtQuick.Controls 2.5, Qt 5.12.4 ) and want to set a
"placeholderText" on the ComboBox to display when no text is entered.

The ComboBox does not have "placeholderText" property and overwriting the
complete contentItem of the ComboBox seems excessive to just do this to
replicate the exsiting functionality (including read only or editable

If I look at the "Fusion/ComboBox.qml" implementation (I am using the
Fusion Style), I can see that the contentItem is implemented using a
"TextField" which means it does support this property.

I have copied the contentItem definition from the implentation and when I
set the placeholderText it behaves correctly.

Is it possible to get access to the TextField used by the original
implemenation and then set the "placeholderText" on it, without the need to
re-implment the complete item?

I have tried the following in the onCompleted handler of the ComboBox
without success:
ComboBox {
  id: comboCategory_

  Component.onCompleted: {
    console.log( "ContentItem is    : " + comboCategory_.contentItem )
    console.log( "placeholderText is: " +
comboCategory_.contentItem.placeholderText )
    comboCategory_.contentItem.placeholderText = "<category>"
    console.log( "placeholderText is: " +
comboCategory_.contentItem.placeholderText )

The ouptut is:
qml: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
qml: ContentItem is    : QQuickTextField(0x17fe84249a0)
qml: placeholderText is:
qml: placeholderText is: <category>
qml: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

But the behaviour does not reflect the change.

Is this something that can be done or should I create a bugreport for a
feature request on the ComboBox element?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190901/c5ff7dfd/attachment.html>

More information about the Interest mailing list