添加菜单的快捷键

This commit is contained in:
一二三 2023-06-20 23:05:02 +08:00
parent c45f1852c6
commit 0a941954e0
3 changed files with 19 additions and 4 deletions

View File

@ -17,6 +17,15 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::onOpenButtonClicked); connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::onOpenButtonClicked);
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::onSaveButtonClicked); connect(ui->actionSave, &QAction::triggered, this, &MainWindow::onSaveButtonClicked);
QIcon openIcon = QApplication::style()->standardIcon(QStyle::SP_DialogOpenButton);
QIcon saveIcon = QApplication::style()->standardIcon(QStyle::SP_DialogSaveButton);
ui->actionOpen->setIcon(openIcon);
ui->actionSave->setIcon(saveIcon);
ui->actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
ui->actionSave->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()

View File

@ -7,6 +7,7 @@
#include <QTableWidget> #include <QTableWidget>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QMimeData> #include <QMimeData>
#include <QShortcut>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
@ -30,5 +31,7 @@ private slots:
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
QProgressDialog* progressDialog; // 添加进度对话框指针 QProgressDialog* progressDialog; // 添加进度对话框指针
QMenu* menuFile;
QAction* actionFile;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -33,12 +33,12 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1400</width> <width>1400</width>
<height>21</height> <height>23</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuOpen"> <widget class="QMenu" name="menuOpen">
<property name="title"> <property name="title">
<string>File</string> <string>文件(&amp;F)</string>
</property> </property>
<addaction name="actionOpen"/> <addaction name="actionOpen"/>
<addaction name="actionSave"/> <addaction name="actionSave"/>
@ -48,12 +48,15 @@
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
<action name="actionOpen"> <action name="actionOpen">
<property name="text"> <property name="text">
<string>Open</string> <string>打开</string>
</property> </property>
</action> </action>
<action name="actionSave"> <action name="actionSave">
<property name="icon">
<iconset theme="Save"/>
</property>
<property name="text"> <property name="text">
<string>Save</string> <string>保存</string>
</property> </property>
</action> </action>
</widget> </widget>