在菜单栏的基础上添加 CreateToolBars();
为按钮添加图标
void MainWindow::CreateActons()
{
this->NewFileAction = new QAction(QIcon("Icons/new.png"), trUtf8("新建"), this);
// this->NewFileAction = new QAction(trUtf8("新建"), this);
this->NewFileAction->setShortcut(trUtf8("Ctrl+N"));
this->NewFileAction->setStatusTip(trUtf8("新建一个文件"));
this->OpenFileAction = new QAction(QIcon("Icons/open.png"), trUtf8("打开"), this);
// this->OpenFileAction = new QAction(trUtf8("打开"), this);
this->OpenFileAction->setShortcut(trUtf8("Ctrl+O"));
this->OpenFileAction->setStatusTip(trUtf8("打开一个文件"));
this->SaveFileAction = new QAction(QIcon("Icons/save.png"), trUtf8("保存"), this);
// this->SaveFileAction = new QAction(trUtf8("保存"), this);
this->SaveFileAction->setShortcut(trUtf8("Ctrl+S"));
this->SaveFileAction->setStatusTip(trUtf8("保存文件"));
}
void MainWindow::CreateToolBars()
{
QList<QAction*> FileActionsList;
FileActionsList << NewFileAction
<< OpenFileAction
<< SaveFileAction;
ui->mainToolBar->addActions(FileActionsList);
}