Results 1 to 3 of 3

Thread: Problem reimplementing QWidget::keyPressEvent

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem reimplementing QWidget::keyPressEvent

    Hi,
    I need to change Tab key behavior for a QTextEdit so that when pressed the focus is passed to the next widget of the parent dialog (in tab order). So I have reimplemented void QWidget::keyPressEvent( QKeyEvent * event ) of my custom QTextEdit this way:

    Qt Code:
    1. void CustomTextEdit::keyPressEvent(QKeyEvent *event)
    2. {
    3. switch (event->key()) {
    4. case Qt::Key_Tab:
    5. emit focusnextchild();
    6. break;
    7. default:
    8. QWidget::keyPressEvent(event);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    but now only the Tab key works (and the next widget is focused); pressing any other key (for inserting text in the textedit, for example) does nothing.

    Where am I wrong?
    Giuseppe CalÃ

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem reimplementing QWidget::keyPressEvent

    did you inherit your widget from QTextEdit?
    if yes, then try
    Qt Code:
    1. ....
    2. default:
    3. QTextEdit::keyPressEvent(event);
    4. ....
    To copy to clipboard, switch view to plain text mode 

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

    jiveaxe (22nd September 2008)

  4. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem reimplementing QWidget::keyPressEvent

    Yes, spirit, you're right. Now works.

    Thanks
    Giuseppe CalÃ

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  3. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 08:12
  4. Replies: 16
    Last Post: 7th March 2006, 15:57

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.