Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change IconSize of QToolButton

Tags:

c++

qt

qtgui

qicon

How to change the IconSize of QToolButton.

button1->setIcon(QIcon("download.jpg"));
button1->setFixedSize(100,100);

By using above code button size is getting change but icon inside the button is not changing.

like image 845
Suresh Avatar asked Jan 15 '14 09:01

Suresh


2 Answers

How about

button1->setFixedSize(100,100);
button1->setIconSize(QSize(100, 100));

If your button lays on the toolbar then use

toolBar->setIconSize(QSize(100, 100));

instead of button icon size changing. If you want to have different sizes on the toolbar then vary them with setFixedSize(). Of course the maximal of them should be QToolBar icon size.

like image 79
dvvrd Avatar answered Nov 16 '22 02:11

dvvrd


From https://qt-project.org/doc/qt-5/qabstractbutton.html#iconSize-prop

You can try using

button1->setIconSize(QSize(100, 100));

Or you can give the button1 size as an argument,

button1->setIconSize(button1->size());

The only downside with this method is that the icons will not be scaled by more than 100% of their original size. If you want icons scaled up, you can try to reimplement the QToolButton::setIconSize method or, as a quick and dirty fix, resize the images using an image editor.

In case of using a QToolBar, use QToolBar::setIconSize method which sets the maximum size icons in the toolbar can have. The icons themselves can be of different size.

like image 3
wolf9000 Avatar answered Nov 16 '22 02:11

wolf9000