Elide text in TextField
-
wrote on 26 Jun 2018, 08:47 last edited by
hello,
i want to know how to elide text in TextField when textField focus change to false.(not entering values in textfield).
thanks,
ayyappa. -
hello,
i want to know how to elide text in TextField when textField focus change to false.(not entering values in textfield).
thanks,
ayyappa.@AYYAPPA
something like this:TextField { id: textField property string fullText: .... // set your actual text content here text: activeFocus ? fullText : metrics.elidedText TextMetrics { id: metrics font: textField.font text: textField.fullText elideWidth: textField.width - 5 } }
(untested)
-
wrote on 26 Jun 2018, 10:25 last edited by
@raven-worx sounds good. i will try and let you know . thanks !!
-
wrote on 27 Jun 2018, 07:27 last edited by
i still feel it would have been better if TextFiled has the ability to store full text and show elided text like Text item.
is there any other qml item which does same job as TextField and has elides text when gone beyond width ??
if you see login page of Instagram , user name filed uses TextField kind of item but does the eliding operation by itself !! -
i still feel it would have been better if TextFiled has the ability to store full text and show elided text like Text item.
is there any other qml item which does same job as TextField and has elides text when gone beyond width ??
if you see login page of Instagram , user name filed uses TextField kind of item but does the eliding operation by itself !!@AYYAPPA
i am not aware of any (input-)control in Qt which has eliding support -
wrote on 27 Jun 2018, 08:59 last edited by
ok thank you
-
@AYYAPPA
something like this:TextField { id: textField property string fullText: .... // set your actual text content here text: activeFocus ? fullText : metrics.elidedText TextMetrics { id: metrics font: textField.font text: textField.fullText elideWidth: textField.width - 5 } }
(untested)
wrote on 22 Aug 2023, 00:55 last edited by Kamichanw@raven-worx This seems cannot work properly. Because when I input text that beyond the
elideWidth
ofmetrics
toTextField
,fullText
will not be updated. Therefore, you should connecttext
withfullText
at least, just like thisConnections { function onTextChanged() { if (text !== metrics.elidedText) fullText = text } }