Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change the IconSize for Actions in QMenu?

Tags:

c++

qt

qmenu

I am trying to resize the Icons of QActions in the QMenu with the following code but it doesn't work.

QMenu *menu;
menu =new QMenu();
menu->setStyleSheet("QMenu::icon{height:20px;width:20px});"

I would really appreciate it if someone could provide a solution.

like image 941
Veera Avatar asked Oct 25 '25 05:10

Veera


1 Answers

We can set style sheet to manage icon size like this:

QAction *action = new QAction("Exit", this);
action->setIcon(QIcon(":/images/resources/exit.png"));


QMenu *menu = new QMenu("File");
menu->addAction(action);
menu->setStyleSheet("QMenu {icon-size: 200px;} QMenu::item {background: transparent;}");

ui->menubar->addMenu(menu);

screenshot

But it will display in an Improper size, so it's better to use QToolBar.

In your cpp file type this:

ui->ToolBarName->setIconSize(QSize(50,50));

In Designer Click on your QToolbar and set iconSize.

image

like image 146
Farhad Avatar answered Oct 26 '25 19:10

Farhad