⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shortcutbutton.cpp

📁 用qt4 编写的局域网聊天工具
💻 CPP
字号:
/*************************************************************************** *   Copyright (C) 2007 by Anistratov Oleg                                 * *   ower86@gmail.com                                                      * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License version 2        * *   as published by the Free Software Foundation;                         * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * ***************************************************************************/#include "shortcutbutton.h"ShortcutButton::ShortcutButton(QWidget *parent) : QPushButton(parent){  setText(tr("Input Shortcut"));}ShortcutButton::~ShortcutButton(){}void ShortcutButton::keyPressEvent(QKeyEvent* ev){  if(ev->isAutoRepeat())    return;  setShortcutText(ev);  if(/*ev->modifiers() &&*/ validKey(ev->key()))  {    emit sequenceAccepted(QKeySequence(ev->modifiers() + validKey(ev->key())));    setText(tr("Input Shortcut"));    releaseKeyboard();  }}void ShortcutButton::keyReleaseEvent(QKeyEvent* ev){  setShortcutText(ev);}int ShortcutButton::validKey(int key){  if(key < 0 || key == Qt::Key_unknown)    return 0;  switch(key)  {    case Qt::Key_Shift   :    case Qt::Key_Control :    case Qt::Key_Alt     :    case Qt::Key_Meta    :    case Qt::Key_AltGr   :    return 0;  }  return key;}void ShortcutButton::setShortcutText(QKeyEvent* ev){  QString seq = QKeySequence(ev->modifiers() + validKey(ev->key())).toString();  if(!seq.isEmpty())    setText(seq);  else    setText(tr("Input Shortcut"));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -