PDA

View Full Version : Adding Image to QPushButton



Seema Rao
8th February 2006, 10:56
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

high_flyer
8th February 2006, 11:26
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".

harish
18th November 2011, 07:12
#include "mainwindow.h"

#include <QtGui/QApplication>
#include<QPushButton>
#include<QIcon>




int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QPushButton *button = new QPushButton ();

button->setIcon(QIcon("favicon.Icon"));

button->show();



return app.exec();
}


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

Lykurg
18th November 2011, 10:06
Do you have the image plugin that handles icon files? Try a png and you hopefully see, that it works.