Hi,

I need to write an application that helps me to interchange the behaviour of the keys,
i.e I need to swap the functionality of the both up arrow and down arrow keys that are present in the keyboard and i am trying to do it using the QKeyEvent.
Is it possible to do so,here is my code please go through it and suggest me where i have done wrong

Here is My HeaderFile
Qt Code:
  1. #ifndef WIDGET_H
  2. #define WIDGET_H
  3.  
  4. #include <QtWidgets>
  5. #include <QEvent>
  6. #include<QTextEdit>
  7. #include<QMessageBox>
  8. class Widget : public QWidget
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13.  
  14. Widget(QWidget *parent = 0);
  15. // QMessageBox box;
  16. // QLabel *txt;
  17. ~Widget();
  18. protected:
  19. bool event(QEvent *);
  20. };
  21.  
  22. #endif // WIDGET_H
To copy to clipboard, switch view to plain text mode 

Here is My ".cpp" File

Qt Code:
  1. #include "widget.h"
  2. #include <QDebug>
  3. #include <QKeyEvent>
  4. #include<QTextEdit>
  5. #include<QString>
  6. #include<QMessageBox>
  7. QString str,str1,str2;
  8. Widget::Widget(QWidget *parent)
  9. : QWidget(parent)
  10. {
  11. qDebug() << "Constructor";
  12.  
  13. //txt= new QLabel(this);
  14. //txt->setGeometry(0,0,320,240);
  15. }
  16.  
  17. Widget::~Widget()
  18. {
  19. qDebug() << "Destructor";
  20. }
  21.  
  22. bool Widget::event(QEvent *e){
  23. //int ret;
  24.  
  25. // qDebug()<<"line num is"<<__LINE__;
  26.  
  27. if(e->type()==QEvent::KeyRelease){
  28. QKeyEvent *ke = static_cast<QKeyEvent *>(e);
  29. int keyValR = ke->key();
  30. qDebug() << "Released key value is : " << keyValR;
  31.  
  32. /* QString str = QString::number(keyValR);
  33.   qDebug()<<str;*/
  34. switch (keyValR) {
  35. case Qt::Key_F1 :
  36. //qDebug()<<__LINE__;
  37. qDebug() << "You have PRESSED :: F1";
  38. //qDebug() << "You have PRESSED :: F1";
  39. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F1</font></b>");
  40. break;
  41. //case 16777265:
  42. case Qt::Key_F2 :
  43. qDebug() << "You have PRESSED :: F2";
  44. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F2</font></b>");
  45. break;
  46. case Qt::Key_F3 :
  47. qDebug() << "You have PRESSED :: F3";
  48. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F3</font></b>");
  49. break;
  50. case Qt::Key_F4 :
  51. qDebug() << "You have PRESSED :: F4";
  52. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F4</font></b>");
  53. break;
  54. case Qt::Key_F5 :
  55. qDebug() << "You have PRESSED :: F5";
  56. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F5</font></b>");
  57. case Qt::Key_F6 :
  58. qDebug() << "You have PRESSED :: F6";
  59. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F6</font></b>");
  60. break;
  61. case Qt::Key_F7 :
  62. qDebug() << "You have PRESSED :: F7";
  63. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F7</font></b>");
  64. break;
  65. case Qt::Key_F8 :
  66. qDebug() << "You have PRESSED :: F8";
  67. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F8</font></b>");
  68. break;
  69. case Qt::Key_F9 :
  70. qDebug() << "You have PRESSED :: F9";
  71. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F9</font></b>");
  72. break;
  73. case Qt::Key_F10 :
  74. qDebug() << "You have PRESSED :: F10";
  75. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F10</font></b>");
  76. break;
  77. case Qt::Key_F11 :
  78. qDebug() << "You have PRESSED :: F11";
  79. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F11</font></b>");
  80. break;
  81. case Qt::Key_F12 :
  82. qDebug() << "You have PRESSED :: F12";
  83. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>F12</font></b>");
  84. break;
  85. case Qt::Key_Return :
  86. qDebug() << "You have PRESSED :: RETURN";
  87. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>RETURN</font></b>");
  88. break;
  89. case Qt::Key_Enter :
  90. qDebug() << "You have PRESSED :: ENTER";
  91. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>ENTER</font></b>");
  92. break;
  93.  
  94. case Qt::Key_Space :
  95. qDebug() << "You have PRESSED :: SPACE";
  96. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>SPACE</font></b>");
  97. break;
  98. case Qt::Key_Shift :
  99. qDebug() << "You have PRESSED :: SHIFT";
  100. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>SHIFT</font></b>");
  101. break;
  102. case Qt::Key_CapsLock :
  103. qDebug() << "You have PRESSED :: CAPSLOCK";
  104. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>CAPSLOCK</font></b>");
  105. break;
  106. case Qt::Key_Delete :
  107. qDebug() << "You have PRESSED :: DELETE";
  108. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>DELETE</font></b>");
  109. break;
  110.  
  111. case Qt::Key_Left:
  112. qDebug() << "You have PRESSED :: <-";
  113. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red> <- </font></b>");
  114. break;
  115. case Qt::Key_Right:
  116. qDebug() << "You have PRESSED ::->";
  117. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>-></font></b>");
  118. break;
  119. case Qt::Key_Down:
  120. qDebug() << "You have PRESSED :: uparrow";
  121. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>UPARROW</font></b>");
  122. break;
  123. case Qt::Key_Up :
  124. qDebug() << "You have PRESSED :: DownArrow";
  125. QMessageBox::information(this,"key pressed", "You have PRESSED :: <b><font color = red>DownArrow</font></b>");
  126. default:
  127. str = ke->text();
  128. qDebug() << "You have PRESSED :: " << str;
  129. str = str.prepend("You have PRESSED :: <b><font color = red>");
  130. str = str.append("</font></b>");
  131. QMessageBox::information(this,"key pressed", str);
  132. break;
  133. }
  134.  
  135.  
  136.  
  137. }
To copy to clipboard, switch view to plain text mode 

Please help me ASAP
Thanks in advance

Regards,
Rohith.G