PDA

View Full Version : QPixmap in QPushButton size problem



MarkoSan
21st January 2008, 20:54
Hi to all!

I've subclassed QPushButton and for the start I would like to resize this god damn QPixmap in subclassed QPushButton! I've been trying for a whole day and I cannot get it to work. Can someone help me?!:crying::confused:

ashukla
22nd January 2008, 09:17
Like MarkoSan, I am facing the same problem using the following code;

#include <QtGui>
int main (int argc, char **argv)
{

QApplication app(argc,argv);
QWidget w;

QPixmap *p=new QPixmap("plane.jpg");
QPixmap *p1=new QPixmap(p->scaled ( 30,20, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ));
QPalette palBack;
QBrush brush(*p1);
brush.setStyle(Qt::TexturePattern);
palBack.setBrush(QPalette::Active, QPalette::Button, brush);
palBack.setBrush(QPalette::Inactive, QPalette::Button, brush);
palBack.setBrush(QPalette::Active, QPalette::Window, brush);
palBack.setBrush(QPalette::Inactive, QPalette::Window, brush);

QBrush brush1(QColor(255, 255, 255, 255));
brush1.setStyle(Qt::SolidPattern);
palBack.setBrush(QPalette::Disabled, QPalette::Button, brush1);
palBack.setBrush(QPalette::Disabled, QPalette::Window, brush1);

w.setPalette(palBack);
QPushButton *lab=new QPushButton(&w);
lab->setGeometry(30,30,40,30);


lab->setPalette(palBack);
lab->setAutoFillBackground (true);
w.show();
w.setFixedSize(300,200);
return app.exec();
}

By using above I am getting the black push button in spite of "plane.jpg". However It is working well for QWidget background. Any help or advice is highly respected.

ashukla
22nd January 2008, 09:21
Output is attached.

MarkoSan
22nd January 2008, 12:50
I managed it to work!!!

setIconSize must be used.