Results 1 to 1 of 1

Thread: [SOLVED] QKeyEventTransition when writing in a QLineEdit

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default [SOLVED] QKeyEventTransition when writing in a QLineEdit

    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:

    Qt Code:
    1. QWidget *win = new QWidget;
    2. QLineEdit *edit = new QLineEdit(win);
    3. QState *searching = ...
    4. ...
    5.  
    6. // When ESC is pressed, clear the field
    7. QKeyEventTransition *pressedEsc = new QKeyEventTransition(edit, QEvent::KeyPress, Qt::Key_Escape);
    8. QObject::connect(pressedEsc, SIGNAL(triggered()), edit, SLOT(clear()));
    9. // and change the state
    10.  
    11. searching->addTransition(pressedEsc);
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by akiross; 30th April 2011 at 01:53. Reason: I forgot to copy addTransition in the code.

Similar Threads

  1. Need help writing my first Qt app
    By netnut in forum Newbie
    Replies: 4
    Last Post: 16th December 2010, 10:52
  2. Replies: 1
    Last Post: 12th October 2010, 22:20
  3. Writing Plugins for Qt
    By sarode in forum Qt Programming
    Replies: 4
    Last Post: 29th May 2006, 09:04
  4. XML file writing
    By mbjerkne in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2006, 19:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.