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
{
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 pixmapmain
(pixmapmain1.
scaled(size
));
let.
setBrush(QPalette::Background,pixmapmain
);
ui->pushButton->setPalette(let);
ui->pushButton->setAutoFillBackground(true);
}
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);
}
To copy to clipboard, switch view to plain text mode
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);
QSize size2
(ui
->pushButton
->width
(),ui
->pushButton
->height
());
QPixmap pixmapmain2
(extpixmap
->scaled
(size2
));
QIcon exticon
(pixmapmain2
);
ui->pushButton->setIconSize(size2);
ui->pushButton->setIcon(exticon);
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);
To copy to clipboard, switch view to plain text mode
Bookmarks