c++qtqmenu

How to Change the IconSize for Actions in 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.


Solution

  • 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