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. How can I substitute one key_character for another?
Qt 6.11 is out! See what's new in the release blog

How can I substitute one key_character for another?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 5.0k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    lsatenstein
    wrote on last edited by
    #1

    // When I receive a Key_UP character, I need to emait a key_Right and with a Key_Down, emit a Key_Left
    // This substitution is only done if a condition shown occurs. I am trying with this code fragment
    //
    // What would I need to add below to achive this.*
    @
    bool MainWindow::eventFilter(QObject *o, QEvent e)
    {
    QString namel;
    if(e->type() != QEvent::KeyPress) /
    only want keypress */
    return (false);

    QKeyEvent *ke =  static_cast<QKeyEvent *>(e);
    QTableWidget *table = static_cast<QTableWidget *>(o);
    name = table->objectName();
    
    if(name== "qt_tabwidget_tabbar")
    {
            //want to absorb Qt::Key_Up and emit Qt::Key_Right;
            //want to absorb Qt::Key_Down and emit Qt::Key_Left;
            if(Qt::Key_Up)
            {
                  // what do I put here
            }
            f(Qt::Key_Down)
            {
                   // what do I put here
            }  
    }
     return(false);
    

    @

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      please use "code wrappings":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 this makes your code more readable.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        d2uriel
        wrote on last edited by
        #3

        Use "this":http://qt-project.org/doc/qt-4.8/qcoreapplication.html#postEvent method.

        "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lsatenstein
          wrote on last edited by
          #4

          Please refer to next post

          1 Reply Last reply
          0
          • D Offline
            D Offline
            d2uriel
            wrote on last edited by
            #5

            I already answered your question. And put your code between @ signs.

            "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lsatenstein
              wrote on last edited by
              #6

              Sorry to everyone for cluttering up the reply area. First, I missed the noting the right most icon which is titled Code. (not realizing it stood for code wrapping).

              Here is the code fragment again. From previous replies to me, please note that I did not see where the key substitution took place or where I could emit an extra character. My excuse and the reason I am asking for help is that I am very new to C++ and to Qt, so have patience with me.

              @
              QKeyEvent *ke = static_cast<QKeyEvent *>(e);
              QTableWidget *table = static_cast<QTableWidget *>(o);
              name = table->objectName();

              if(name== "qt_tabwidget_tabbar")
              {
                  if((ke->key()==Qt::Key_UP)                                                 
                  {
                      //qDebug()<< "Want to replace Qt:Key_UP with a Qt:Key_Left"           
                  }
                  else
                  if((ke->key()==Qt::Key_Down)                                                 
                  {
                      //qDebug()<< "Want to replace Qt:Key_Down with a Qt:Key_Right"            
                  }
                  return(false);
              }
              

              @

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Please do not re-post your code, but just edit your posts. The link is to the right of the post, just below username and avatar.

                The place where you have the (commented) qDebug()s is the correct one to fire the postEvent method.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lsatenstein
                  wrote on last edited by
                  #8

                  Hi Everybody.

                  Here is some additional information to use, if you can help me. I created a tableform, but the toplevel selection icons are on the side. To move up or down the 4 or 5 top levels (keyboard only), I have to use the keyboard's left arrow or right arrow keys.

                  I know when I am on these icons as detailed by my preceding showing lines entry lines 7-15. I need tu issue a Qt::Key_left after intercepting a Qt::key_Down.

                  I was not certain but is the Qtest facility the only way to solve this? Here is a code fragment.
                  @
                  if (ke->key() == Qt::Key_Up)
                  QTest::keyClick(myWidget, Qt::Key_Left);
                  @

                  I tried to #include <QTest>, it was not found. Do I have to put something into the pro file to indicate where to find it or do I haev to use a fully qualified path?

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dbzhang800
                    wrote on last edited by
                    #9

                    QtTest module is designed to assistant you to test your application.
                    @
                    QT += testlib
                    @
                    But don't use this module in normal application in other cases.


                    In addition, d2uriel and Volker had told you how to do.

                    1 Reply Last reply
                    0

                    • Login

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