Results 1 to 2 of 2

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

  1. #1
    Join Date
    Jan 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default How to display text in a push button on top of (not above) an icon?

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to display text in a push button on top of (not above) an icon?

    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,
    _

Similar Threads

  1. adding image and text both to a push button
    By Charvi in forum Qt Programming
    Replies: 5
    Last Post: 3rd August 2012, 09:44
  2. Replies: 1
    Last Post: 1st August 2011, 08:17
  3. push button icon not shows???
    By chandantheracer in forum Newbie
    Replies: 2
    Last Post: 25th February 2011, 13:08
  4. How to change text color of push button?
    By augusbas in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2009, 11:32
  5. Designing the display content of a push button
    By cookie1909 in forum Newbie
    Replies: 4
    Last Post: 16th April 2009, 23:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.