Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QKeySequence(tr("Ctrl+X, Ctrl+C"));
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 1 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on 9 Nov 2012, 17:14 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tucnak
      wrote on 9 Nov 2012, 17:35 last edited by
      #2

      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
      }
      }
      @

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on 9 Nov 2012, 18:08 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tucnak
          wrote on 9 Nov 2012, 19:12 last edited by
          #4

          [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)).

          1 Reply Last reply
          0

          1/4

          9 Nov 2012, 17:14

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved