Skip to content

Commit 261f12d

Browse files
author
Alexis Lopez Zubieta
committed
Add action whith icon which is loaded from the system theme
1 parent c639c5f commit 261f12d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

QtWidgetsApplication/mainwindow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ MainWindow::MainWindow(QWidget *parent) :
66
ui(new Ui::MainWindow)
77
{
88
ui->setupUi(this);
9+
QAction *action = new QAction(this);
10+
QIcon icon;
11+
auto iconThemeName = QStringLiteral("list-add");
12+
if (QIcon::hasThemeIcon(iconThemeName)) {
13+
icon = QIcon::fromTheme(iconThemeName);
14+
} else {
15+
icon.addFile(QStringLiteral("."), QSize(), QIcon::Normal, QIcon::Off);
16+
}
17+
action->setIcon(icon);
18+
ui->mainToolBar->addAction(action);
919
}
1020

1121
MainWindow::~MainWindow()

0 commit comments

Comments
 (0)