PDA

View Full Version : [SOLVED] QKeyEventTransition when writing in a QLineEdit



akiross
30th April 2011, 02:43
Hello,
I'm writing a stateful application, in which a Search state is present. While in this state, the user is writing in a QLineEdit. The user input may have 2 results: if the user presses Return, the search is performed, if the user presses Escape, the search is aborted.

I'm using QKeyEventTransition to get the key presses and moving around the states, but when the user is writing in the QLineEdit, the transition is not performed.
I used it as this:



QWidget *win = new QWidget;
QLineEdit *edit = new QLineEdit(win);
QState *searching = ...
...

// When ESC is pressed, clear the field
QKeyEventTransition *pressedEsc = new QKeyEventTransition(edit, QEvent::KeyPress, Qt::Key_Escape);
QObject::connect(pressedEsc, SIGNAL(triggered()), edit, SLOT(clear()));
// and change the state

searching->addTransition(pressedEsc);


This doesn't work with Key_Escape nor with Key_Return. I also tried to change "edit" to "win" in the QKeyEventTransition - thinking that maybe the events were forwarded - but doesn't work.

The only thing I can do (which works) is to use the returnPressed() signal and connect it to clear(), but I need to do the same with the Escape key and also changing the state, so I think a KeyEventTransition would be better than a SignalTransition.
Using a SignalTransition would require (I think) to define a signal in QLineEdit every time I need a particular key handling.

Can someone help me understanding why QKeyEventTransition doesn't get any keypress event when writing in the QLineEdit? How can I solve the problem?
Thanks in advance
~Aki

SOLVED:
Sorry, I solved. The QKeyEventTransition works like expected even with QLineEdit. I just missed a parameter in my code.