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()<<"快捷键已占用";
    }


}

 

相关文章:

  • 2021-12-14
  • 2022-12-23
  • 2021-08-14
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
相关资源
相似解决方案