How to change IconSize of QToolButton
Asked Answered
E

2

19

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.

Eject answered 15/1, 2014 at 9:32 Comment(0)
N
27

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.

Nesto answered 15/1, 2014 at 9:46 Comment(3)
Yes it worked. But if i want to set 1st button icon size to (100,100) and other to (200,200) then what should i doEject
The size in toolBar is the maximum size toolbar icons can have. Set it to some maximum value and use lower (different) values for icons.Shawnna
@Rupesh, edited the answer. In that case you should assign (200, 200) to toolbar and (100, 100) to button`s fixed sizeNesto
S
3

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.

Shawnna answered 15/1, 2014 at 9:52 Comment(3)
Is your button1 created using Qt Designer? Can you check if there are any properties you may have accidentally set (shown in bold) that may prevent the method from resizing the button? Is the button part of a layout or a grid?Shawnna
NO i have not created is using QTDesigner. QToolButton is a part of QToolBar and QtoolBar is a part of layout. Button size is enhancing but not icon sizeEject
You should use QToolBar::setIconSize also.Shawnna

© 2022 - 2024 — McMap. All rights reserved.