QAction* newAction = new QAction("New Action", this); QIcon icon(":/myIcon.png"); //assuming icon is in a resource file newAction->setIcon(icon);
ui->action_New->setIcon(QIcon::fromTheme("document-new"));In this example, an existing QAction object is obtained from a widget's UI using the ui->action_New syntax. The icon for this action is then set using the QIcon::fromTheme function, which retrieves a standard icon from the current icon theme based on the supplied name "document-new". The package library used in these code examples is the Qt framework.