gpt-4-0613· OpenAI
Arena Human Preference 55K
PyQt6 python. Howto set text into a QLabel where a part of the text has a different color?
- User
PyQt6 python. Howto set text into a QLabel where a part of the text has a different color?
- Assistant
To change the color of a part of the text in a QLabel in PyQt6, you can use HTML style formatting. Here is how you can do it:
pythonfrom PyQt6.QtWidgets import QApplication, QLabel, QMainWindow import sys class MainWindow(QMainWindow): def __init__(self): super().__init__() # Make sure to use setTextFormat to Qt.TextFormat.RichText to allow HTML formatting self.label = QLabel() self.label.setTextFormat(Qt.Qt.TextFormat.RichText) # Use HTML style tags to set the color of the text self.label.setText("This is <span style='color:red'>colored</span> text") self.setCentralWidget(self.label) app = QApplication(sys.argv) window = MainWindow() window.show() app.exec()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.