2

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. I am using both QlineEdit and QTextEdit objects.

 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

You can use an HTML declaration to change the text color inside a text box.

An example is given on the following link: color in a qt text box

And here is an example of how to change only one letter: one letter color

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.