Results 1 to 5 of 5

Thread: QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog

  1. #1
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog

    Hello,

    I am not quite sure about that, but it seems that, the QDialogButtonBox always causes that the OK button is "clicked" when the Enter button is pressed in the dialog.
    The setDefault and setAutoDefault for contained buttons seems not to work.

    Could anybody confirm this behavior? How to prevent this.
    I'd like that the pressing of the Enter button causes, that the cursor moves to the next field.

    Thx

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog

    For me it works fine.

    The Enter press is caught only when the ButtonBox has the focus.
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog

    Quote Originally Posted by mcosta View Post
    For me it works fine.

    The Enter press is caught only when the ButtonBox has the focus.
    I am pressing Enter when I finish editing in QLineEdit ==> QLineEdit has focus, though
    the OK ButtonBox sends the clicked() signal

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog

    It's true and it's a features of QDialog.

    To avoid it you have to reimplement QDialog::keyPressEventIn example

    Qt Code:
    1. void MyDialog::keyPressEvent(QKeyEvent *e)
    2. {
    3. switch (e->key ()) {
    4. case Qt::Key_Return:
    5. case Qt::Key_Enter:
    6. qDebug ("Return/enter pressed");
    7. // Do your work
    8. break;
    9.  
    10. default:
    11. QDialog::keyPressEvent (e);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog

    Thanks for the answer.
    I think I've found the more simple solution. That's only QDialogButtonBox that reacts in this way on Enter button. When instead of of it I use separate QPushButtons everything works perfect.

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2011, 20:21
  2. "Render" Qt dialog window from ".ui" file
    By BitEater in forum Qt Programming
    Replies: 1
    Last Post: 8th July 2011, 15:40
  3. Replies: 5
    Last Post: 17th June 2011, 10:43
  4. How to "hide window when close button pressed"
    By iGoo in forum Qt Programming
    Replies: 4
    Last Post: 26th July 2006, 10:53

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.