首页 > 其他分享 >Qt之QToolBar使用

Qt之QToolBar使用

时间:2022-12-13 11:00:41浏览次数:38  
标签:Qt void QAction mainwindow QMessageBox 使用 include MainWindow QToolBar

 

 

.pro

 1 QT       += core gui
 2 
 3 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 4 
 5 CONFIG += c++11
 6 
 7 # The following define makes your compiler emit warnings if you use
 8 # any Qt feature that has been marked deprecated (the exact warnings
 9 # depend on your compiler). Please consult the documentation of the
10 # deprecated API in order to know how to port your code away from it.
11 DEFINES += QT_DEPRECATED_WARNINGS
12 
13 # You can also make your code fail to compile if it uses deprecated APIs.
14 # In order to do so, uncomment the following line.
15 # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
17 
18 SOURCES += \
19     main.cpp \
20     mainwindow.cpp
21 
22 HEADERS += \
23     mainwindow.h
24 
25 FORMS += \
26     mainwindow.ui
27 
28 # Default rules for deployment.
29 qnx: target.path = /tmp/$${TARGET}/bin
30 else: unix:!android: target.path = /opt/$${TARGET}/bin
31 !isEmpty(target.path): INSTALLS += target
View Code

main.cpp

 1 #include "mainwindow.h"
 2 
 3 #include <QApplication>
 4 
 5 int main(int argc, char *argv[])
 6 {
 7     QApplication a(argc, argv);
 8     MainWindow w;
 9     w.show();
10     return a.exec();
11 }
View Code

mainwindow.h

 1 #ifndef MAINWINDOW_H
 2 #define MAINWINDOW_H
 3 
 4 #include <QMainWindow>
 5 //
 6 #include <QMenu>
 7 #include <QMenuBar>
 8 #include <QToolBar>
 9 #include <QAction>
10 #include <QMessageBox>
11 #include <QDebug>
12 #include <QLabel>
13 
14 QT_BEGIN_NAMESPACE
15 namespace Ui { class MainWindow; }
16 QT_END_NAMESPACE
17 
18 class MainWindow : public QMainWindow
19 {
20     Q_OBJECT
21 
22 public:
23     MainWindow(QWidget *parent = nullptr);
24     ~MainWindow();
25 
26     void craeteMenuBar();
27     void craeteToolBar();
28     void craeteStatusBar();
29 public slots:
30     void clickcutToolbarAction();
31     void clickitalicToolbarAction();
32 private:
33     QMenu*     m_menu;
34     QAction*   m_newMenu;
35     QAction*   m_openMenu;
36 
37     QToolBar* m_Toolbar;
38     QAction* m_Action1;
39     QAction* m_Action2;
40     QAction* m_Action3;
41     QAction* m_Action4;
42 
43     Ui::MainWindow *ui;
44 };
45 #endif // MAINWINDOW_H
View Code

mainwindow.cpp

 1 #include "mainwindow.h"
 2 #include "ui_mainwindow.h"
 3 
 4 MainWindow::MainWindow(QWidget *parent)
 5     : QMainWindow(parent)
 6     , ui(new Ui::MainWindow)
 7 {
 8     ui->setupUi(this);
 9 
10     craeteToolBar();
11 }
12 
13 MainWindow::~MainWindow()
14 {
15     delete ui;
16 }
17 
18 void MainWindow::craeteToolBar()
19 {
20     //方法1:构建工具栏
21     //m_Toolbar = addToolBar("file");
22     //方法2:构建工具栏
23     m_Toolbar = new QToolBar(this);
24     this->addToolBar(m_Toolbar);
25     m_Action1 = new QAction("A",this);
26     m_Action2 = new QAction("B",this);
27     m_Action3 = new QAction("C",this);
28     m_Action4 = new QAction("D",this);
29     m_Toolbar->addAction(m_Action1);
30     m_Toolbar->addAction(m_Action2);
31     m_Toolbar->addAction(m_Action3);
32     m_Toolbar->addAction(m_Action4);
33     connect(m_Action1, SIGNAL(triggered()), this, SLOT(clickcutToolbarAction()));
34     connect(m_Action2, SIGNAL(triggered()), this, SLOT(clickitalicToolbarAction()));
35 }
36 
37 void MainWindow::clickcutToolbarAction()
38 {
39     QMessageBox MyBox(QMessageBox::Question,"Title","cutToolBar",QMessageBox::Yes | QMessageBox::No);
40     MyBox.exec();
41 }
42 
43 void MainWindow::clickitalicToolbarAction()
44 {
45     QMessageBox MyBox(QMessageBox::Question,"Title","italicToolBar",QMessageBox::Yes | QMessageBox::No);
46     MyBox.exec();
47 }
View Code

mainwindow.ui

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <ui version="4.0">
 3  <class>MainWindow</class>
 4  <widget class="QMainWindow" name="MainWindow">
 5   <property name="geometry">
 6    <rect>
 7     <x>0</x>
 8     <y>0</y>
 9     <width>505</width>
10     <height>214</height>
11    </rect>
12   </property>
13   <property name="windowTitle">
14    <string>MainWindow</string>
15   </property>
16   <widget class="QWidget" name="centralwidget"/>
17   <widget class="QMenuBar" name="menubar">
18    <property name="geometry">
19     <rect>
20      <x>0</x>
21      <y>0</y>
22      <width>505</width>
23      <height>22</height>
24     </rect>
25    </property>
26   </widget>
27   <widget class="QStatusBar" name="statusbar"/>
28  </widget>
29  <resources/>
30  <connections/>
31 </ui>
View Code

 

搜索

复制

<iframe></iframe>

标签:Qt,void,QAction,mainwindow,QMessageBox,使用,include,MainWindow,QToolBar
From: https://www.cnblogs.com/FKdelphi/p/16977981.html

相关文章

  • 关于el-descriptions-item自定义使用方法
    如果有错请及时点出,虚心接受各位大佬提醒-----------开发不容易且行且珍惜显示类似于原生的table表格的列形式exportdefault{components:{},name:'n......
  • Clipboard 复制粘贴的使用
    首先npminstallclipboard安装依赖;clipboard.js1importVuefrom'vue'2importClipboardfrom'clipboard'34functionclipboardSuccess(){5Vu......
  • 【IDEA】使用 IDEA 之前的准备工作
       设置代码模板 /***@Title:*@Description:*@Version:v1.0*@Author:Mr.Guan*@[email protected]*@DateTime:${YEAR}-${MONTH}-${DAY}${HOUR}......
  • 使用TensorFlow Probability实现最大似然估计
    TensorFlowProbability是一个构建在TensorFlow之上的Python库。它将我们的概率模型与现代硬件(例如GPU)上的深度学习结合起来。极大似然估计最大似然估计是深度学习模......
  • QT商品管理系统(数据库)
    QT商品管理系统(数据库)功能需求:在Linux系统内设计一个图形界面(GUI)的商品管理程序,必须实现对数据库的操作,以及提供,添加,查询,修改,删除和显示已存储数据等功能。设计要......
  • 使用v-html指令的禁忌和解决xss注入攻击
    1.由于v-html会执行所有的html代码,因此会执行所有可能带危险的html代码  2.在使用v-html时为了防止XSS攻击,可以安装npminstallxss插件,但是我们在渲染富文本编辑的......
  • 使用DevExpress WPF主题设计器轻松创建Office 2019绿色主题(二)
    DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专......
  • Centos 7配置使用nginx反向代理mysql
    背景:由于WEB服务和MySQL数据库服务分开部署的,由于网络问题限制,有时需要通过中间代理服务器跳转连接MySQL,所以需要在中间服务器上配置代理。1、添加stearm模块#nginx通常......
  • Windows系统使用nvm-windowas进行node版本管理
    下载nvm:https://github.com/coreybutler/nvm-windows/releases(nvm-setup.zip)nvm一些常见命令:nvmlist:查看已安装版本nvmlistavailable:查看可安装的node版......
  • sys_stat_statements 扩展使用介绍
    sys_stat_statements模块提供追踪服务器所执行的所有SQL语句的执行统计信息,可以用于统计数据库的资源开销,如分析TOPSQL。KingbaseESV8R6版本该插件已经内置化,初始化数......