Results 1 to 4 of 4

Thread: Adding Image to QPushButton

  1. #1
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Adding Image to QPushButton

    Hi all,

    I am using Qt version 4.0.1. I am trying to add a Image on QPushButton
    So here is the program I have written,

    #include <QtGui>
    #include <QPushButton>
    int main( int argc, char **argv )
    {
    QApplication a( argc, argv );
    QPushButton *button = new QPushButton ("Rock and Roll");
    button->setPixmap(QPixmap(" Door.bmp"));
    button->show();
    return a.exec();
    }


    But it gives compilation "error no matching function for call to `QPushButton::setPixmap(QPixmap)'"
    Can some body explain how to do it? Same lines are explained in Qt 4.01.
    but I dont know why its not compiling?


    Thanks in Advance,
    Seema Rao

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding Image to QPushButton

    In Qt4 QPushButton has no setPixmap() method.
    Use setIcon() instead.
    Push buttons display a textual label, and optionally a small icon. These can be set using the constructors and changed later using setText() and setIcon(). If the button is disabled the appearance of the text and icon will be manipulated with respect to the GUI style to make the button look "disabled".

  3. #3
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post Re: Adding Image to QPushButton

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. #include <QtGui/QApplication>
    4. #include<QPushButton>
    5. #include<QIcon>
    6.  
    7.  
    8.  
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication app(argc, argv);
    13.  
    14. QPushButton *button = new QPushButton ();
    15.  
    16. button->setIcon(QIcon("favicon.Icon"));
    17.  
    18. button->show();
    19.  
    20.  
    21.  
    22. return app.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Hi all i am new to qt and i am trying to add images to Qpushbutton but i was not to get the image displayed in the button?I dont know where i go wrong can anyone help me with this ?
    Here is the code which i have tried.


    Regards,
    Harish
    Last edited by Lykurg; 18th November 2011 at 09:06. Reason: missing [code] tags

  4. #4
    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: Adding Image to QPushButton

    Do you have the image plugin that handles icon files? Try a png and you hopefully see, that it works.

Similar Threads

  1. QPushButton with image - text alignment
    By vladeck in forum Newbie
    Replies: 3
    Last Post: 1st July 2009, 19:20
  2. QPushButton with image on it
    By msmihai in forum Newbie
    Replies: 1
    Last Post: 6th January 2009, 20:53
  3. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  4. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  5. BG image on QPushButton using style sheets??
    By JimDaniel in forum Newbie
    Replies: 2
    Last Post: 13th September 2007, 03:31

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.