How can I substitute one key_character for another?



  • // 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);
    

    @


  • Moderators

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





  • Please refer to next post



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



  • 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);
    }
    

    @



  • 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.



  • 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?



  • 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.


Log in to reply
 

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