0

Here's a code snippet:

QLabel *lbl = new QLabel("Current Value : <span>100 V</span>");    
lbl->setStyleSheet("color:#000000; font-size:14px;");    
lbl->setStyleSheet("QLabel span { font-size:18px; }");

How to use two different styles in one string in Qt?
I tried but it does not work.

Is there any method to do this type of style?
Any suggestions would be highly appreciated. Thanks!

Azeem
  • 11,148
  • 4
  • 27
  • 40
Senthil Kumar
  • 562
  • 1
  • 6
  • 14
  • https://stackoverflow.com/questions/23490017/how-to-add-style-via-setstylesheet-without-losing-orignal-style-in-qt something like this? – Chirag Acharya Jun 26 '17 at 11:19

1 Answers1

2

As each HTML tag can have its own style attribute so you can do something like this in span:

QLabel *lbl = new QLabel( "Current Value : <span style='font-size:18px;'>100 V</span>" );

lbl->setStyleSheet( "color:#000000; font-size:14px;" );

Here's a snapshot: enter image description here

Azeem
  • 11,148
  • 4
  • 27
  • 40
  • This is QT Framework, here this type of inline style in span is not allowed.. This way is not working. – Senthil Kumar Jun 26 '17 at 11:01
  • @SenthilKumar: I've posted my answer after testing it first. I've updated it with a snapshot of the output. BTW, you can customize Qt Widgets that are quite comfortable rendering `HTML`. Here's the [Qt Style Sheets Reference](http://doc.qt.io/qt-5/stylesheet-reference.html) if you are interested to learn more. – Azeem Jun 26 '17 at 11:32
  • Thank Azeem, Its working i tried.. Previously i tried in setStylesheet i used span not working. But now using setText i used.. Now working.. Thanks for effort.. – Senthil Kumar Jun 27 '17 at 04:39
  • @SenthilKumar: My pleasure! :) I'm glad I could help. – Azeem Jun 27 '17 at 04:44