QT5入门之11 - 工具栏
2015-10-15 17:32
453 查看
工具栏和菜单栏是联系在一起的。
QAction能够根据添加的位置来改变自己的样子——如果添加到菜单中,就会显示成一个菜单项;如果添加到工具条,就会显示成一个按钮。
效果如下:
void exit();
其中 QIcon(“:/images/exit”) 是引用资源文件中的图片,需要添加qrc文件(菜单文件-新建-Qt-Qt resourcefile)。
qrc文件内容如下(右键qrc-添加现有文件):
QAction能够根据添加的位置来改变自己的样子——如果添加到菜单中,就会显示成一个菜单项;如果添加到工具条,就会显示成一个按钮。
openAction = new QAction(QIcon(":/images/open"), tr("&Open..."), this); openAction->setShortcuts(QKeySequence::Open); openAction->setStatusTip(tr("Open an existing file")); connect(openAction, &QAction::triggered, this, &MainWindow::open);//&MainWindow? QMenu *file = menuBar()->addMenu(tr("&File")); file->addAction(openAction); exitAction = new QAction(QIcon(":/images/exit"), tr("&Exit..."), this); exitAction->setShortcuts(QKeySequence::Close); exitAction->setStatusTip(tr("exit the app")); connect(exitAction, &QAction::triggered, this, &MainWindow::exit); file->addAction(exitAction); // QMenu *edit = menuBar()->addMenu(tr("&Edit")); edit->addAction(exitAction); QToolBar *toolBar = addToolBar(tr("&File")); toolBar->addAction(openAction); toolBar->addAction(exitAction); // ui->mainToolBar->addAction(openAction); // ui->mainToolBar->addAction(exitAction);
效果如下:
void exit();
其中 QIcon(“:/images/exit”) 是引用资源文件中的图片,需要添加qrc文件(菜单文件-新建-Qt-Qt resourcefile)。
qrc文件内容如下(右键qrc-添加现有文件):
<RCC> <qresource prefix="/"> <file>images/open.png</file> <file>images/exit.png</file> </qresource> </RCC>
相关文章推荐
- QT5入门之10 - 启动程序失败,路径或者权限错误
- Qt 中使用智能指针
- pyqt4中对话框模态和非模态
- QT5入门之9 - 菜单栏
- QT5入门之8 - 定时器
- 【Qt】调用WindowsMediaPlayer进行视频播放=文章未整理=
- qt窗口部件的布局
- Qt中Model/View
- Qt下 QString转char*
- QT5入门之7 - 修改程序图标
- Qt 进程通信QSharedMemory
- QT5入门之7 - Qt禁止最大化最小化
- 使用QThread和QTimer的发现
- QT5入门之6 - Qt提示对话框
- QT5入门之5 - 确认退出对话框
- QT5入门之4 - 窗口总在最前
- QT5入门之3 - Qt Creator常用快捷键
- arm-linux下qt + opencv开发环境的搭建(Altera DE1 Soc)
- Qt OpenCV windows下配置
- QT移植