I want to set an image on QPushButton
, and the size of QPushButton
should depend on the size of the image. I am able to do this when using QLabel
, but not with QPushButton
.
So, if anyone has a solution, then please help me out.
Just click on your button then go to icon property and then choose your image file.
To use these icons within Qt Designer you would select the drop-down and choose "Set Icon From Theme..." You then enter the name of the icon you want to use, e.g. document-new (the full list of valid names). If you're not using designer, you can set icons from a theme in your code using the following.
The QToolButton class provides a quick-access button to commands or options, usually used inside a QToolBar.
What you can do is use a pixmap as an icon and then put this icon onto the button.
To make sure the size of the button will be correct, you have to reisze the icon according to the pixmap size.
Something like this should work :
QPixmap pixmap("image_path"); QIcon ButtonIcon(pixmap); button->setIcon(ButtonIcon); button->setIconSize(pixmap.rect().size());
QPushButton *button = new QPushButton; button->setIcon(QIcon(":/icons/...")); button->setIconSize(QSize(65, 65));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With