Added example
This commit is contained in:
parent
7ab3b98a5c
commit
38127fffef
|
@ -0,0 +1,26 @@
|
||||||
|
#include "Widget.h"
|
||||||
|
|
||||||
|
#include <QKeySequence>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
Widget::Widget(QWidget *parent) :
|
||||||
|
QWidget(parent),
|
||||||
|
m_globalShortcut(new QxtGlobalShortcut(QKeySequence("Shift+F1"), this))
|
||||||
|
{
|
||||||
|
QObject::connect(m_globalShortcut, SIGNAL(activated()), this, SLOT(shortcutActivated()));
|
||||||
|
|
||||||
|
setWindowTitle(QString("Press %1").arg(m_globalShortcut->shortcut().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget::~Widget()
|
||||||
|
{
|
||||||
|
if(m_globalShortcut) {
|
||||||
|
m_globalShortcut->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::shortcutActivated()
|
||||||
|
{
|
||||||
|
activateWindow();
|
||||||
|
QMessageBox::critical(this, "Shortcut activated!", QString("You pressed %1").arg(m_globalShortcut->shortcut().toString()));
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef WIDGET_H
|
||||||
|
#define WIDGET_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
#include "qxtglobalshortcut.h"
|
||||||
|
|
||||||
|
class Widget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Widget(QWidget *parent = 0);
|
||||||
|
~Widget();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void shortcutActivated();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QxtGlobalShortcut *m_globalShortcut;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WIDGET_H
|
|
@ -0,0 +1,14 @@
|
||||||
|
QT += core gui
|
||||||
|
|
||||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
TARGET = demo
|
||||||
|
TEMPLATE = app
|
||||||
|
SOURCES += \
|
||||||
|
main.cpp \
|
||||||
|
Widget.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
Widget.h
|
||||||
|
|
||||||
|
include(../../QxtGlobalShortcut.pri)
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include "Widget.h"
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
Widget w;
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
Loading…
Reference in New Issue