Problem with QKeySequence(tr("Ctrl+X, Ctrl+C"));



  • Hello. The Qt documentation says:

    @For example, the key sequence, Ctrl X followed by Ctrl C, can be specified using either of the following ways:
    QKeySequence(tr("Ctrl+X, Ctrl+C"));
    QKeySequence(Qt::CTRL + Qt::Key_X, Qt::CTRL + Qt::Key_C);@

    but it doesn't work for me. When I change the first part with another letter, for example Ctrl+D, Ctrl+C, it's ok.
    Maybe it is because Ctrl+X and Ctrl+C are standard keys. I found that there is bug report -> https://bugreports.qt-project.org/browse/QTBUG-8767 (version 4.6.2). Should I override the keyPressEvent or there is another solution? Thank you very much.



  • Hi, ~MrDev!

    Welcome to Qt Developer Network!

    It's not good practise to use QKeySequence and QShortcut to work with this kind of shortcuts. If you are really need to implement it you should to do it in this way:
    @
    void MyHappyWidget::keyPressEvent(QKeyEvent *e) {
    if(e->key() == Qt::Key_X && e->modifiers() == Qt::ControlModifier) {
    // code here
    }
    }
    @



  • Hi, tucnak. Thank you for your reply.

    yes, that was my version...
    @void MyWidget::keyPressEvent(QKeyEvent *event) {

    switch (event->key()) {
        case Qt::Key_X:
            if (event->modifiers() & Qt::ControlModifier) {
                qDebug() << "yep";
            }
            break;
    
        default:
            QWidget::keyPressEvent(event);
    }
    

    }@

    It doesn't work again. When I change the Qt::Key_X with Qt::Key_Z for example, it is ok. But with the letters X,C,V it doesn't.



  • [quote author="MrDev" date="1352484489"]Hi, tucnak. Thank you for your reply.

    yes, that was my version...
    @void MyWidget::keyPressEvent(QKeyEvent *event) {

    switch (event->key()) {
        case Qt::Key_X:
            if (event->modifiers() & Qt::ControlModifier) {
                qDebug() << "yep";
            }
            break;
    
        default:
            QWidget::keyPressEvent(event);
    }
    

    }@

    It doesn't work again. When I change the Qt::Key_X with Qt::Key_Z for example, it is ok. But with the letters X,C,V it doesn't. [/quote]

    Hm... it should be interesting. Sorry, I am busy today, so you should wait for other users or tomorrow)).


Log in to reply
 

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