I've had the same problem (if I've read yours correctly). I've tried several approaches to have text written across the icon on a QPushButton. This is what finally worked for me:
Working code:
QPixmap pixmap
(":/Icons/icon.png");
pixmap
=pixmap.
scaled(QSize(ui
->appButton
->width
(),ui
->appButton
->height
()),Qt
::IgnoreAspectRatio,Qt
::SmoothTransformation);
palette.
setBrush(ui
->appButton
->backgroundRole
(),
QBrush(pixmap
));
ui->appButton->setFlat(true);
ui->appButton->setAutoFillBackground(true);
ui->appButton->setPalette(palette);
QPixmap pixmap(":/Icons/icon.png");
pixmap=pixmap.scaled(QSize(ui->appButton->width(),ui->appButton->height()),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
QPalette palette;
palette.setBrush(ui->appButton->backgroundRole(),QBrush(pixmap));
ui->appButton->setFlat(true);
ui->appButton->setAutoFillBackground(true);
ui->appButton->setPalette(palette);
To copy to clipboard, switch view to plain text mode
What did not work (text at the side) was:
ui->appButton->setFlat(true);
ui->appButton->setAutoFillBackground(true);
QIcon img
(":/Icons/icon.png");
ui->appButton->setIcon(img);
ui
->appButton
->setIconSize
(QSize(ui
->appButton
->width
(),ui
->appButton
->height
()));
ui->appButton->setFlat(true);
ui->appButton->setAutoFillBackground(true);
QIcon img(":/Icons/icon.png");
ui->appButton->setIcon(img);
ui->appButton->setIconSize(QSize(ui->appButton->width(),ui->appButton->height()));
To copy to clipboard, switch view to plain text mode
What I could not use (no scaling possible) was:
ui->appButton->setStyleSheet("background-image: url(:/Icons/icin.png);");
ui->appButton->setStyleSheet("background-image: url(:/Icons/icin.png);");
To copy to clipboard, switch view to plain text mode
Bookmarks