> -----Original Message----- > From: Interest <interest-boun...@qt-project.org> On Behalf Of Carel > Combrink > Sent: Sunday, 1 September 2019 9:22 PM > To: interest <interest@qt-project.org> > Subject: [Interest] QML: PlaceholderText on ComboBox (Controls 2) > > Hi, > > 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 > behaviour) > > 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: > {code} > ComboBox { > id: comboCategory_ > ... > > Component.onCompleted: { > console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") > console.log( "ContentItem is : " + comboCategory_.contentItem ) > console.log( "placeholderText is: " + > comboCategory_.contentItem.placeholderText ) > comboCategory_.contentItem.placeholderText = "<category>" > console.log( "placeholderText is: " + > comboCategory_.contentItem.placeholderText ) > console.log("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") > } > > } > {code} > > The ouptut is: > {code} > qml: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > qml: ContentItem is : QQuickTextField(0x17fe84249a0) > qml: placeholderText is: > qml: placeholderText is: <category> > qml: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb > > {code} > > But the behaviour does not reflect the change.
That should work (and it appears to from the output), so I'm not sure why you don't see the placeholder text, assuming that is the actual issue here. > Is this something that can be done or should I create a bugreport for a > feature request on the ComboBox element? The way you're doing it in onCompleted is the easiest way to do it currently, and it should work. Can you please post a minimal example here so we can see why it's not working first? As for a feature request, you can create one if you want. I wonder if something like Nils' idea of exposing a textField property would be the best solution to this: https://bugreports.qt.io/browse/QTBUG-71406?focusedCommentId=438916&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-438916 Usually the contentItem is a TextField, but if it's not, it would just be null. The problem is that this same issue likely applies to lots of other controls, and it might end up in a slippery slope of adding these type-specific accessor properties. > Regards, > Carel _______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest