PDA

View Full Version : How to display text in a push button on top of (not above) an icon?



dave2
21st October 2015, 07:57
Hi,

I need to display a push button (for example an instance of QPushButton) which would contain an icon and text.

I do not want the text to show beside, above or below the icon. I want the text to show ON TOP OF the icon. That is, I want the icon to be centered in the push button, and I also want the text to be centered in the push button. Then the text will hide part of the icon below it, and that's OK.

I have found several threads on this and other forums explaining how to display text beside, above or below an icon within a push button, but nothing that would solve what I want.

Any idea?

anda_skoa
24th October 2015, 17:20
1) Determine the size of the text, e.g. using QFontMetrics.
2) Create a QPixmap with that size.
3) Paint the icon into that pixmap on the wanted position.
4) Paint the text on the pixmap.
5) Use that pixmap on the button

Cheers,
_