Is it possible to have two different Font size for the QPushButton? For example, for the text "LIVE VIDEO' in a QPushButton, I want to have the font-size 16 for 'LIVE' and 12 for 'VIDEO'.
Asked
Active
Viewed 928 times
2 Answers
3
Derive from QPushButton and draw the text yourself. You can refer this post for reference. Two colours text in QPushButton

abhilb
- 5,639
- 2
- 20
- 26
0
While what @abhilb suggests is possible I would go with a custom QLabel
that is clickable, which is faster to implement.
Unlike QPushButton
QLabel
supports rich text formatting. If you set the text formatting to Qt::RichText
you can put HTML inside meaning you can use <font/>
, <b/>
etc.
myLabel.setTextFormat(Qt::RichText);
myLabel.setText("<font size='16'>LIVE</font><font size='12'/>VIDEO</font>");
I've added this formatting to a label in a widget of mine and you can see the results:
You just need to handle the void mouseReleaseEvent(QMouseEvent* event);
or void mousePressEvent(QMouseEvent* event);
in order to make it properly clickable. The final touch would be to emit your own clicked()
signal.

rbaleksandar
- 8,713
- 7
- 76
- 161
-
Yea but even with click handlers it still won't look or act anything like a button unless you go all the way and style it properly including hover/press and all that. And it still won't look like the rest of the application unless all the push buttons are styled the same way. Re-implementing paintEvent() seems much simpler IMHO. – Maxim Paperno Nov 13 '19 at 22:57