彻底改版2.0
This commit is contained in:
40
third/hotkey/frmhotkey.cpp
Normal file
40
third/hotkey/frmhotkey.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "frmhotkey.h"
|
||||
#include "ui_frmhotkey.h"
|
||||
#include "qhotkey.h"
|
||||
#include "qdatetime.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
frmHotKey::frmHotKey(QWidget *parent) : QWidget(parent), ui(new Ui::frmHotKey)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->initForm();
|
||||
}
|
||||
|
||||
frmHotKey::~frmHotKey()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void frmHotKey::initForm()
|
||||
{
|
||||
//this->setWindowFlags(Qt::FramelessWindowHint);
|
||||
|
||||
//实例化热键类 支持各种组合形式比如 ctrl+a alt+a f2
|
||||
QHotkey *hotkey = new QHotkey(QKeySequence("ctrl+a"), true, this);
|
||||
connect(hotkey, SIGNAL(activated()), this, SLOT(shortcut()));
|
||||
}
|
||||
|
||||
void frmHotKey::shortcut()
|
||||
{
|
||||
#if 1
|
||||
//如果是最小化则显示,否则最小化
|
||||
if (this->isMinimized()) {
|
||||
this->showNormal();
|
||||
this->activateWindow();
|
||||
} else {
|
||||
this->showMinimized();
|
||||
}
|
||||
#else
|
||||
ui->label->setText("activated " + QTime::currentTime().toString("hh:mm:ss zzz"));
|
||||
#endif
|
||||
}
|
||||
26
third/hotkey/frmhotkey.h
Normal file
26
third/hotkey/frmhotkey.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef FRMHOTKEY_H
|
||||
#define FRMHOTKEY_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class frmHotKey;
|
||||
}
|
||||
|
||||
class frmHotKey : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit frmHotKey(QWidget *parent = 0);
|
||||
~frmHotKey();
|
||||
|
||||
private:
|
||||
Ui::frmHotKey *ui;
|
||||
|
||||
private slots:
|
||||
void initForm();
|
||||
void shortcut();
|
||||
};
|
||||
|
||||
#endif // FRMHOTKEY_H
|
||||
31
third/hotkey/frmhotkey.ui
Normal file
31
third/hotkey/frmhotkey.ui
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>frmHotKey</class>
|
||||
<widget class="QWidget" name="frmHotKey">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>全局热键示例</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>按 ctrl+x 最小化,再次按显示</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
16
third/hotkey/hotkey.pro
Normal file
16
third/hotkey/hotkey.pro
Normal file
@@ -0,0 +1,16 @@
|
||||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
|
||||
|
||||
TARGET = hotkey
|
||||
TEMPLATE = app
|
||||
DESTDIR = $$PWD/../bin
|
||||
CONFIG += warn_off
|
||||
|
||||
SOURCES += main.cpp
|
||||
SOURCES += frmhotkey.cpp
|
||||
HEADERS += frmhotkey.h
|
||||
FORMS += frmhotkey.ui
|
||||
|
||||
INCLUDEPATH += $$PWD/../3rd_qhotkey
|
||||
include($$PWD/../3rd_qhotkey/3rd_qhotkey.pri)
|
||||
10
third/hotkey/main.cpp
Normal file
10
third/hotkey/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "frmhotkey.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
frmHotKey w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user