Qt - style characters from index x to the end

44 Views Asked by At

How to style characters from index x (eg. x=10) to end of text in QLineEdit?

Example:

Text in QLineEdit:

0123456789

And I want make characters from index 2 (that is 2) to the end should be bold.

0123456789

1

There are 1 best solutions below

0
On

QLineedit is a one line of plain text which you may not easily handle such character formatting. On the other hand Qt provides text widgets for plain and rich text, that can accept formatting such as html. For instance the QTextEdit widget can be used and render such formatting of text with html tags.

QString html = "01<b>23456789</b>";
QTextEdit::setHtml(html);