#include "widget.h"
#include <QDebug>
#include <QKeyEvent>
#include<QTextEdit>
#include<QString>
#include<QMessageBox>
{
qDebug() << "Constructor";
//txt= new QLabel(this);
//txt->setGeometry(0,0,320,240);
}
Widget::~Widget()
{
qDebug() << "Destructor";
}
bool Widget
::event(QEvent *e
){ //int ret;
// qDebug()<<"line num is"<<__LINE__;
if(e
->type
()==QEvent::KeyRelease){ int keyValR = ke->key();
qDebug() << "Released key value is : " << keyValR;
/* QString str = QString::number(keyValR);
qDebug()<<str;*/
switch (keyValR) {
case Qt::Key_F1 :
//qDebug()<<__LINE__;
qDebug() << "You have PRESSED :: F1";
//qDebug() << "You have PRESSED :: F1";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F1</font></b>");
break;
//case 16777265:
case Qt::Key_F2 :
qDebug() << "You have PRESSED :: F2";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F2</font></b>");
break;
case Qt::Key_F3 :
qDebug() << "You have PRESSED :: F3";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F3</font></b>");
break;
case Qt::Key_F4 :
qDebug() << "You have PRESSED :: F4";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F4</font></b>");
break;
case Qt::Key_F5 :
qDebug() << "You have PRESSED :: F5";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F5</font></b>");
case Qt::Key_F6 :
qDebug() << "You have PRESSED :: F6";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F6</font></b>");
break;
case Qt::Key_F7 :
qDebug() << "You have PRESSED :: F7";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F7</font></b>");
break;
case Qt::Key_F8 :
qDebug() << "You have PRESSED :: F8";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F8</font></b>");
break;
case Qt::Key_F9 :
qDebug() << "You have PRESSED :: F9";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F9</font></b>");
break;
case Qt::Key_F10 :
qDebug() << "You have PRESSED :: F10";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F10</font></b>");
break;
case Qt::Key_F11 :
qDebug() << "You have PRESSED :: F11";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F11</font></b>");
break;
case Qt::Key_F12 :
qDebug() << "You have PRESSED :: F12";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>F12</font></b>");
break;
case Qt::Key_Return :
qDebug() << "You have PRESSED :: RETURN";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>RETURN</font></b>");
break;
case Qt::Key_Enter :
qDebug() << "You have PRESSED :: ENTER";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>ENTER</font></b>");
break;
case Qt::Key_Space :
qDebug() << "You have PRESSED :: SPACE";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>SPACE</font></b>");
break;
case Qt::Key_Shift :
qDebug() << "You have PRESSED :: SHIFT";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>SHIFT</font></b>");
break;
case Qt::Key_CapsLock :
qDebug() << "You have PRESSED :: CAPSLOCK";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>CAPSLOCK</font></b>");
break;
case Qt::Key_Delete :
qDebug() << "You have PRESSED :: DELETE";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>DELETE</font></b>");
break;
case Qt::Key_Left:
qDebug() << "You have PRESSED :: <-";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red> <- </font></b>");
break;
case Qt::Key_Right:
qDebug() << "You have PRESSED ::->";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>-></font></b>");
break;
case Qt::Key_Down:
qDebug() << "You have PRESSED :: uparrow";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>UPARROW</font></b>");
break;
case Qt::Key_Up :
qDebug() << "You have PRESSED :: DownArrow";
QMessageBox::information(this,
"key pressed",
"You have PRESSED :: <b><font color = red>DownArrow</font></b>");
default:
str = ke->text();
qDebug() << "You have PRESSED :: " << str;
str = str.prepend("You have PRESSED :: <b><font color = red>");
str = str.append("</font></b>");
break;
}
}
#include "widget.h"
#include <QDebug>
#include <QKeyEvent>
#include<QTextEdit>
#include<QString>
#include<QMessageBox>
QString str,str1,str2;
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
qDebug() << "Constructor";
//txt= new QLabel(this);
//txt->setGeometry(0,0,320,240);
}
Widget::~Widget()
{
qDebug() << "Destructor";
}
bool Widget::event(QEvent *e){
//int ret;
// qDebug()<<"line num is"<<__LINE__;
if(e->type()==QEvent::KeyRelease){
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
int keyValR = ke->key();
qDebug() << "Released key value is : " << keyValR;
/* QString str = QString::number(keyValR);
qDebug()<<str;*/
switch (keyValR) {
case Qt::Key_F1 :
//qDebug()<<__LINE__;
qDebug() << "You have PRESSED :: F1";
//qDebug() << "You have PRESSED :: F1";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F1</font></b>");
break;
//case 16777265:
case Qt::Key_F2 :
qDebug() << "You have PRESSED :: F2";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F2</font></b>");
break;
case Qt::Key_F3 :
qDebug() << "You have PRESSED :: F3";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F3</font></b>");
break;
case Qt::Key_F4 :
qDebug() << "You have PRESSED :: F4";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F4</font></b>");
break;
case Qt::Key_F5 :
qDebug() << "You have PRESSED :: F5";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F5</font></b>");
case Qt::Key_F6 :
qDebug() << "You have PRESSED :: F6";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F6</font></b>");
break;
case Qt::Key_F7 :
qDebug() << "You have PRESSED :: F7";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F7</font></b>");
break;
case Qt::Key_F8 :
qDebug() << "You have PRESSED :: F8";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F8</font></b>");
break;
case Qt::Key_F9 :
qDebug() << "You have PRESSED :: F9";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F9</font></b>");
break;
case Qt::Key_F10 :
qDebug() << "You have PRESSED :: F10";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F10</font></b>");
break;
case Qt::Key_F11 :
qDebug() << "You have PRESSED :: F11";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F11</font></b>");
break;
case Qt::Key_F12 :
qDebug() << "You have PRESSED :: F12";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F12</font></b>");
break;
case Qt::Key_Return :
qDebug() << "You have PRESSED :: RETURN";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>RETURN</font></b>");
break;
case Qt::Key_Enter :
qDebug() << "You have PRESSED :: ENTER";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>ENTER</font></b>");
break;
case Qt::Key_Space :
qDebug() << "You have PRESSED :: SPACE";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>SPACE</font></b>");
break;
case Qt::Key_Shift :
qDebug() << "You have PRESSED :: SHIFT";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>SHIFT</font></b>");
break;
case Qt::Key_CapsLock :
qDebug() << "You have PRESSED :: CAPSLOCK";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>CAPSLOCK</font></b>");
break;
case Qt::Key_Delete :
qDebug() << "You have PRESSED :: DELETE";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>DELETE</font></b>");
break;
case Qt::Key_Left:
qDebug() << "You have PRESSED :: <-";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red> <- </font></b>");
break;
case Qt::Key_Right:
qDebug() << "You have PRESSED ::->";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>-></font></b>");
break;
case Qt::Key_Down:
qDebug() << "You have PRESSED :: uparrow";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>UPARROW</font></b>");
break;
case Qt::Key_Up :
qDebug() << "You have PRESSED :: DownArrow";
QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>DownArrow</font></b>");
default:
str = ke->text();
qDebug() << "You have PRESSED :: " << str;
str = str.prepend("You have PRESSED :: <b><font color = red>");
str = str.append("</font></b>");
QMessageBox::information(this,"key pressed", str);
break;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks