Results 1 to 4 of 4

Thread: How to add two icons/images to the same QPushButton??

  1. #1
    Join Date
    Feb 2011
    Posts
    23
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default How to add two icons/images to the same QPushButton??

    Hi,
    How to add two icons/images to the same QPushButton.
    ie, i want to add one icon with alignment left and another in the center besdes to the text ??
    i'm doing the following but it shows only one icon
    Qt Code:
    1. championbtn=new QPushButton;
    2. championbtn->setText("any");
    3. championbtn->setIcon(QIcon(":/images/DEFAULT-LOGO.png"));
    4. championbtn->setIcon(QIcon(":/images/CLOSE.png"));
    5. championbtn->setIconSize(QSize(31,31));
    To copy to clipboard, switch view to plain text mode 
    thanks
    Ram
    Last edited by wysota; 1st April 2011 at 13:12. Reason: reformatted to look better

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to add two icons/images to the same QPushButton??

    setIcon will only set one image
    Qt Code:
    1. championbtn->setIcon(QIcon(":/images/DEFAULT-LOGO.png"));
    2. championbtn->setIcon(QIcon(":/images/CLOSE.png"));
    To copy to clipboard, switch view to plain text mode 
    in this code , the CLOSE.png will be set to the button.
    simple solution will be just add the two images in imageeditor. and load it.

    hope it helps
    Bala

  3. #3
    Join Date
    Feb 2011
    Posts
    23
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: How to add two icons/images to the same QPushButton??

    thanks bala,
    i'm newbie to QT and don't know how to do that, so please give me sample code, link or more details
    thanks

  4. #4
    Join Date
    Jul 2010
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to add two icons/images to the same QPushButton??

    Hi ram4soft,

    Instead of you can merger two images and then apply them to the pushbutton

    The syntax can be like this...

    Qt Code:
    1. QIcon dummyIcon;
    2. QPixmap comboPixmap(50, 25);
    3. QPixmap firstImage(":/QTTestProject/images/Image-01.png"); //qrc path
    4. QPixmap secondImage(":/QTTestProject/images/Image-02.png"); //qrc path
    5.  
    6. QPainter painter(&comboPixmap);
    7. painter.drawPixmap(0, 0, firstImage);
    8. painter.drawPixmap(firstImage.width(), 0, secondImage);
    9.  
    10. dummyIcon.addPixmap(comboPixmap);
    11.  
    12. championbtn->setIcon(dummyIcon);
    To copy to clipboard, switch view to plain text mode 

    Note: Set the comboPixmap size based on the "Image-01.png" and "Image-02.png".

Similar Threads

  1. How to show images from database as icons in QListView
    By LeshaS in forum Qt Programming
    Replies: 2
    Last Post: 21st January 2011, 07:13
  2. Using QStyle for QPushButton with 3 background images.
    By suslik in forum Qt Programming
    Replies: 1
    Last Post: 9th July 2010, 05:42
  3. Images/icons. It's not displayed
    By LMZ in forum Qt Tools
    Replies: 37
    Last Post: 18th May 2007, 14:55
  4. Replies: 3
    Last Post: 26th September 2006, 12:16
  5. SVG icons on a QPushButton?
    By Kumula in forum Qt Programming
    Replies: 2
    Last Post: 22nd May 2006, 21:03

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.