QKeySequence 预设快捷键
最后更新于:2022-04-02 02:10:56
[TOC]
## 概述
统一了Windows,macOS,KDE,GNOME的快捷键
使用:
```
// 4种方式相同
QKeySequence(QKeySequence::Print);
QKeySequence(tr("Ctrl+P"));
QKeySequence(tr("Ctrl+p"));
QKeySequence(Qt::CTRL + Qt::Key_P);
```
## 实例
### simple
```
QAction *openfile = new QAction(tr("测试"),this);
openfile->setIcon(QIcon(":/1.jpeg"));
openfile->setShortcut(QKeySequence::Open);
openfile->setText("test");
openfile->setIconText("test2");
connect(openfile,&QAction::triggered,this,&MainWindow::open);
ui->toolBar->addAction(openfile);
```
';