Block keyboard in QDialog

  • Hi
    how to block keys like 'Esc' , 'up' , 'Down' , 'Right' ...... on keyboard?
    like i pressed 'Esc' key dialog don't close

  • Qt Champions 2016

    Block for a Dialog or for whole application ?

    In many cases, using event filter might work good.

    or for just dialog

    MyDialog::keyPressEvent(QKeyEvent *e) {
        if(e->key() != Qt::Key_Escape)
        else {/* minimize */}

  • I want use the keys but don't effect on Dialog
    I want set shortcut keys for my app like Qt Creator in Option>Environment>Keyboard when Record button is clicked keys not effect on Dialog & any key is pressed show in a QLineEdit
    How can i do this?

  • Create event filter to filter required keys and install filter on ur dialog which is not supposed to receive the keys. This filter you can install for any widget you want.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.