-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmy_line_edit.cpp
48 lines (43 loc) · 1.09 KB
/
my_line_edit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "my_line_edit.h"
#include <iostream>
#include <QKeyEvent>
myLineEdit::myLineEdit(QWidget *parent) : QLineEdit(parent), tgt(NULL)
{
}
void myLineEdit::keyPressEvent(QKeyEvent * event)
{
QString seq = QString::null;
Qt::KeyboardModifiers mods = event->modifiers();
if(mods & Qt::ShiftModifier){
seq += QString::fromUtf8("Shift+");
}
if(mods & Qt::ControlModifier){
seq += QString::fromUtf8("Ctrl+");
}
if(mods & Qt::AltModifier){
seq += QString::fromUtf8("Alt+");
}
if(mods & Qt::MetaModifier){
seq += QString::fromUtf8("Meta+");
}
int k = event->key();
//std::cout<<"Key event -> '"<<k<<std::endl;
switch(k){
case 0:
case Qt::Key_unknown:
case Qt::Key_Shift:
case Qt::Key_Control:
case Qt::Key_Alt:
case Qt::Key_Meta:
break;
default:
seq += QKeySequence(event->key()).toString(QKeySequence::NativeText);
setText(seq);
if(tgt != NULL){
*tgt = seq;
}
//std::cout<<"Key event -> '"<<seq.toUtf8().constData()<<"' !"<<k<<std::endl;
break;
}
//QLineEdit::keyPressEvent(event);
}