在网上收到的注册QT全局热键的方法,基本都不支持QT5,查了大量资料发现QT5不支持QAbstractEventDispatcher::EventFilter;参考资料进行了更改,使用如下:
代码:
https://download.youkuaiyun.com/download/sinat_35178307/10810536
使用方法:
#include "./sethotkey/qxtglobalshortcut.h"
QxtGlobalShortcut* m_pHotKey;
//注册热键
void initHotKey()
{
m_strHotKey = "Ctrl+H";
m_pHotKey = new QxtGlobalShortcut(QKeySequence(m_strHotKey));
connect(m_pHotKey, SIGNAL(activated()), this, SLOT(slotHotKeyEvent()));
}
//删除热键
void DeleteShortcut()
{
m_pHotKey->setDisabled();
//
}
void slotHotKeyEvent
{
//do something
}
参考:
https://blog.youkuaiyun.com/dbzhang800/article/details/6302816
https://blog.youkuaiyun.com/trustguan/article/details/39270865?utm_source=blogxgwz3