PDA

View Full Version : how to stretch background image of pushbutton on button resize?



athulms
29th September 2011, 09:41
how to stretch background image of pushbutton on button resize?

i tryed this code. But not worked at all. its works for frame, central widgets, labels but not working on pushbutton



void MainWindow::resizeEvent(QResizeEvent *e)
{
ui->centralWidget->setGeometry(0,0,e->size().width(),e->size().height());
ui->pushButton->setGeometry(0,0,(e->size().width())/2,(e->size().height())/2);
QPalette let = ui->pushButton->palette();
QSize size(ui->pushButton->width(),ui->pushButton->height());
QString main=":/M_alertBtncontinueUpNews.png";
QPixmap pixmapmain1(main);
QPixmap pixmapmain(pixmapmain1.scaled(size));
let.setBrush(QPalette::Background,pixmapmain);
ui->pushButton->setPalette(let);
ui->pushButton->setAutoFillBackground(true);
}

Added after 22 minutes:

i got the code...
this worked for me

ui->centralWidget->setGeometry(0,0,e->size().width(),e->size().height());
ui->pushButton->setGeometry(0,0,(e->size().width())/2,(e->size().height())/2);
QPixmap* extpixmap = new QPixmap(":/M_alertBtncontinueUpNews.png");
QSize size2(ui->pushButton->width(),ui->pushButton->height());
QPixmap pixmapmain2(extpixmap->scaled(size2));
QIcon exticon(pixmapmain2);
ui->pushButton->setIconSize(size2);
ui->pushButton->setIcon(exticon);