Qt全局热键第三方库qxtglobalshortcut5使用
1.下载第三方库https://github.com/ddqd/qxtglobalshortcut5
2.把qxtglobalshortcut5文件放在项目目录下,在项目.pro加入一句,include(qxtglobalshortcut5-master/qxt.pri)
3.使用,包含头文件#include “qxtglobalshortcut.h”
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include "qxtglobalshortcut.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QxtGlobalShortcut *shortcut = new QxtGlobalShortcut(this);
if(shortcut->setShortcut(QKeySequence("Shift+1")))
{
connect(shortcut, &QxtGlobalShortcut::activated,
[=]() {qDebug() << "shortcut activated";});
}
else
{
qDebug()<<"快捷键已占用";
}
}