0

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

Guruku
  • 653
  • 1
  • 7
  • 6
  • You'd need to modify the style's rendering code, perhaps by having a proxy style that runs on top of the existing style. You'd be reimplementing the control drawing code for this particular scenario. – Kuba hasn't forgotten Monica Jul 01 '18 at 04:05

1 Answers1

0

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);
Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47