Results 1 to 12 of 12

Thread: How to disable enter

  1. #1
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to disable enter

    in my dialog a pushbutton (named Yes) is there.
    in constructor i gave like

    Qt Code:
    1. connect(this->yesButton,SIGNAL(clicked()),this,SLOT(accept()));
    To copy to clipboard, switch view to plain text mode 

    I dont want to accept this dailog if Enter key from keyboard is pressed. how to disable the focus. Only if i mouseclick on this button it should accept. How to do?
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable enter

    use eventFilter on the pushButton and filter the key press
    bool myclass:: eventFilter(QObject *ob, QEvent *e)
    {
    if(ob == pushbutton && e->type() == QEvent::KeyPress) {
    xxxx
    return true;
    }
    return QWidget::eventFilter(ob, e);
    }
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable enter

    Quote Originally Posted by wagmare View Post
    use eventFilter on the pushButton and filter the key press
    bool myclass:: eventFilter(QObject *ob, QEvent *e)
    {
    if(ob == pushbutton && e->type() == QEvent::KeyPress) {
    xxxx
    return true;
    }
    return QWidget::eventFilter(ob, e);
    }
    Hi wagmare,
    its not working. if i press enter key also its closeing the dialog.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable enter

    show the filter code u implemented .. did u use installEventFilter on pushButton
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable enter

    Quote Originally Posted by wagmare View Post
    show the filter code u implemented .. did u use installEventFilter on pushButton
    i used like

    bool CDialog::eventFilter(QObject *i_Object, QEvent *i_Event)
    {
    if(i_Object == yesButton && i_Event->type() == QEvent::KeyPress)
    {
    return true;
    }
    else
    return QWidget::eventFilter(i_Object, i_Event);
    }

    void CDialog::installEventFilter ( QObject * filterObj )
    {
    this->installEventFilter(yesButton);
    }
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  6. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable enter

    include this inside the if() condition
    const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    if(ke->key()==Qt::Key_Enter /** or use Qt::Key_Enter **/){
    return false;

    and use simply use
    yesButton->installEventFilter(this);
    "Behind every great fortune lies a crime" - Balzac

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to disable enter

    Quote Originally Posted by phillip_Qt View Post
    I dont want to accept this dailog if Enter key from keyboard is pressed. how to disable the focus. Only if i mouseclick on this button it should accept. How to do?
    Set the focus policy of the button object to NoFocus and set its 'default' and 'autoDefault' properties to false.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable enter

    Quote Originally Posted by wysota View Post
    Set the focus policy of the button object to NoFocus and set its 'default' and 'autoDefault' properties to false.
    No it didnt help. its closing the dialog. i need diloag not to be executed untill i press yesbutton.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to disable enter

    Could you provide a minimal compilable example reproducing the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable enter

    Quote Originally Posted by wysota View Post
    Could you provide a minimal compilable example reproducing the problem?
    herewith i've attched the code. if i press pushbutton, a new pop up is coming. if i press enter key from keyboard its closing the pop up. i need the pop up should be accepted if i mouse click yes button or rejected in No button.
    Attached Files Attached Files
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to disable enter

    Strange... when I change your code to do what I told you to do in my first post it... works correctly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12

    Default Re: How to disable enter

    maybe you should use Qt::Key_Return instead of Qt::Key_Enter.
    Qt::Key_Enter is the keypad Enter.

Similar Threads

  1. Replies: 1
    Last Post: 14th September 2008, 23:05
  2. Process Enter Key on QTableWidget
    By kandalf in forum Qt Programming
    Replies: 5
    Last Post: 9th May 2007, 15:31
  3. qtextedit capturing the enter key
    By tas in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2007, 00:35
  4. QEvent::Enter
    By incapacitant in forum Newbie
    Replies: 6
    Last Post: 22nd March 2006, 08:07
  5. [QT3] QComboBox: Disable adding items on Enter-keypress
    By BrainB0ne in forum Qt Programming
    Replies: 7
    Last Post: 14th January 2006, 19:43

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.