PDA

View Full Version : Show variable in color on UI



dennisvz
9th January 2019, 19:46
I would like to show the value of the variable "filestatus" in the following line of code in blue. How?



self.ui.title.setText(str("My Tax Info Based on a Filing Status of: " + filestatus))


Thanks

d_stranz
9th January 2019, 21:43
If "title" is a QLabel, you can format your string in Rich Text Format (RTF) (https://doc.qt.io/qt-5/richtext.html) using the subset of HTML (https://doc.qt.io/qt-5/richtext-html-subset.html)supported by the rich text engine.



self.ui.title.setText(str("My Tax Info Based on a Filing Status of: <font color=blue>" + filestatus + "</font>" ))

dennisvz
9th January 2019, 22:04
If "title" is a QLabel, you can format your string in Rich Text Format (RTF) (https://doc.qt.io/qt-5/richtext.html) using the subset of HTML (https://doc.qt.io/qt-5/richtext-html-subset.html)supported by the rich text engine.



self.ui.title.setText(str("My Tax Info Based on a Filing Status of: <font color=blue>" + filestatus + "</font>" ))


perfect, thanks