Results 1 to 3 of 3

Thread: qtextedit capturing the enter key

  1. #1
    Join Date
    Feb 2007
    Posts
    4

    Default qtextedit capturing the enter key

    I need to have rich text editing in a qlineedit so I am altering a qtextedit to work the same. I have succeeded in everything except I need to capture the enter key to make it submit.

    My problem now is I can capture the enter key but it captures all keys and the rest dont make it to the text area. So I am trying to ignore the event when it is any other key but the enter key but it doesnt ignore the event and still captures them. Does anyone have any ideas?

    Qt Code:
    1. void InputBox::keyPressEvent(QKeyEvent *event){
    2. if(event->key()==Qt::Key_Return){
    3. doAction()
    4. }
    5. else event->ignore();
    6. }
    To copy to clipboard, switch view to plain text mode 

    I tried inserting the text manually into the text area but I ran into the problem of other keys such as the backspace trying to be inserted which shows up as a box

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qtextedit capturing the enter key

    Try:
    Qt Code:
    1. void InputBox::keyPressEvent(QKeyEvent *event){
    2. if(event->key()==Qt::Key_Return){
    3. doAction()
    4. }
    5. else {
    6. QTextEdit::keyPressEvent( event );
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2007
    Posts
    4

    Default Re: qtextedit capturing the enter key

    Thank you that worked perfectly.

Similar Threads

  1. QTextEdit, sizeHint, QWidget
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2007, 08:25
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  3. QTextEdit and "Enter" press
    By krivenok in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2006, 12:10
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 14:47

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.