Results 1 to 3 of 3

Thread: Keyboard event and QTextEdit

  1. #1
    Join Date
    Oct 2009
    Location
    Poland
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Keyboard event and QTextEdit

    Hello,
    i have problem with handling keyboard event, the problem is related to QTextEdit Widget the point is:
    i have QTextEdit object for example called writeTextEdit and i installed on it event filter
    Qt Code:
    1. this->writeTextEdit->installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 

    next i implement eventFilter method
    Qt Code:
    1. bool FooClass::eventFilter(QObject* _o, QEvent* _e){
    2. if(_e->type() == QEvent::KeyPress){
    3. QKeyEvent* eventKey = static_cast<QKeyEvent*>(_e);
    4. if(eventKey->key() == Qt::Key_Return){
    5. //do something
    6. }
    7. return true;
    8. }else{
    9. return QObject::eventFilter(_o, _e);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    and when i run my app and want to write something in QTextEdit no letters are show inside, what is the problem?

    Best Regards
    kaszewczyk

  2. #2
    Join Date
    Nov 2008
    Location
    Italy
    Posts
    16
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Keyboard event and QTextEdit

    For what i see in your code for every key is pressed you check if the key is return then do something. if you are not pressing the return key you simply return true you should return the BaseClass eventFilter (thinking that FooClass extends QTextEdit).

    Well maybe something like that:

    Qt Code:
    1. bool FooClass::eventFilter(QObject* _o, QEvent* _e)
    2. {
    3. if(_e->type() == QEvent::KeyPress)
    4. {
    5. QKeyEvent* eventKey = static_cast<QKeyEvent*>(_e);
    6. if(eventKey->key() == Qt::Key_Return)
    7. {
    8. //do something
    9. return true;
    10. }
    11. }
    12. return QTextEdit::eventFilter(_o, _e);
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Corinzio; 2nd November 2009 at 18:56.

  3. The following user says thank you to Corinzio for this useful post:

    kaszewczyk (2nd November 2009)

  4. #3
    Join Date
    Oct 2009
    Location
    Poland
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Keyboard event and QTextEdit

    Thanks work well

    Best Regards
    kaszewczyk

Similar Threads

  1. Replies: 2
    Last Post: 10th April 2009, 02:06
  2. QTextEdit does not show!!!!
    By MarkoSan in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2008, 15:13
  3. MousePressEvent for QTextEdit
    By anju123 in forum Qt Programming
    Replies: 9
    Last Post: 16th August 2007, 06:08
  4. Re-implement mouse events of QTextEdit
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2006, 16:55
  5. a question about visualizing cursor in read-only QTextEdit
    By kennyxing in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2006, 19:52

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.