Results 1 to 3 of 3

Thread: Scale an image and assign it to a QPushButton

  1. #1
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Scale an image and assign it to a QPushButton

    Hello!

    I'd like to set the background image of one QPushButtons, but I'd like a scaled baskground, so the image should adapt to the button dimnsion.
    Using SetStyleSheet did'nt work for me. I tried even with che QPixmap::scaled() assigning it to the SetIcon method of the button but the image is shown very little...anyone has any idea?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Scale an image and assign it to a QPushButton

    Have you had a look at "QPushButton and images" at the Qt Style Sheets Examples?
    Otherwise you have to subclass QPushButton and do the background drawing yourself.

  3. #3
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Scale an image and assign it to a QPushButton

    I solved using this code:

    Qt Code:
    1. QIcon img("/img/ico.bmp");
    2. button.setIcon(img);
    3. button.setIconSize(QSize(button.width(), button.height()));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Adding Image to QPushButton
    By Seema Rao in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2011, 09:06
  2. how to scale a picture/image?
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 26th May 2010, 12:51
  3. QPushbutton with background image when disabled
    By soumyadeep_pan in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2009, 15:50
  4. QPushButton Icon Image
    By QbelcorT in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2009, 14:26
  5. QPushButton with image on it
    By msmihai in forum Newbie
    Replies: 1
    Last Post: 6th January 2009, 20:53

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.