0

I need to highlight the particular letter in a text box using python. I am using the below code but it changes the entire text color in text box. Kindly suggest any other ideas.

 if self.dlgAttribute.ui.txtPartDesc3.text()!="":
        partDescValue = self.dlgAttribute.ui.txtPartDesc3.text()
        if not partDescValue in self.englishArray:
            font.setPointSize(11)
            self.dlgAttribute.ui.txtPartDesc3.setFont(font)
            self.dlgAttribute.ui.txtPartDesc3.setStyleSheet(_fromUtf8("color: rgb(255, 162, 0);\n"
            "background-color: rgb(41, 91, 170);\n"
            "font: 750 10pt \"Arial\";"))
        else:
            font.setPointSize(11)
            self.dlgAttribute.ui.txtPartDesc3.setFont(font)
            self.dlgAttribute.ui.txtPartDesc3.setStyleSheet(_fromUtf8("color: rgb(0,0,0);\n"
            "background-color: rgb(255, 255, 255);\n"
            "font: 750 10pt \"Arial\";"))
    else:
        font.setPointSize(11)
        self.dlgAttribute.ui.txtPartDesc3.setFont(font)
        self.dlgAttribute.ui.txtPartDesc3.setStyleSheet(_fromUtf8("color: rgb(0,0,0);\n"
        "background-color: rgb(255, 255, 255);\n"
        "font: 750 10pt \"Arial\";"))

1 Answers1

0

One way to do it is, use a rich text box which is read only, then copy the content of plain text of input box and replace the texts which you'd like to highlight into QTextFormat or so on.

https://doc.qt.io/qt-5/richtext.html

Or, more easy way is that, convert your text into HTML, then dynamically render it by QWebView.

Displaying (rendering) HTML from a string in QT

fumiya.f
  • 255
  • 3
  • 13
  • This is not a web application, it is a stand alone desktop application which has simple user form developed using Python 2.7 and QT designer 4. – venkat Oct 31 '19 at 05:41