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 to assign TAB to ENTER or RETURN key in TableView?

How to assign TAB to ENTER or RETURN key in TableView?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 514 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.
  • MucipM Offline
    MucipM Offline
    Mucip
    wrote on last edited by
    #1

    Hi,
    As you know we can move between the cells by TAB key in TableView. But I want to use RETURN or ENTER key.
    I tryed event filter but could not get it.

    bool ProfilKesim::eventFilter(QObject *object, QEvent *event)
    {
        if(event->type() == QEvent::KeyPress){
            QKeyEvent* key = static_cast<QKeyEvent*>(event);
    
            if ( (key->key()==Qt::Key_Enter) || (key->key()==Qt::Key_Return) )
            {
                if(object==ui->tVDetay) /*This mean thet TableView?*/
                {
                         /*I tryed this but no result?*/         
                        /*I need to assign TAB to ENTER key here!!!!*/                      
                    QApplication::postEvent(this, new QKeyEvent(key->type(), Qt::Key_Tab, key->modifiers());
                }else focusNextChild();
            }
    
        }
    
    
        return false;
    }
    

    Regards,
    Mucip:)

    1 Reply Last reply
    0
    • MucipM Offline
      MucipM Offline
      Mucip
      wrote on last edited by
      #2

      Hi,
      I found solution here...

      Shortly:

      QKeyEvent * eve1 = new QKeyEvent (QEvent::KeyPress,Qt::Key_A,Qt::NoModifier,"a");
      QKeyEvent * eve2 = new QKeyEvent (QEvent::KeyRelease,Qt::Key_A,Qt::NoModifier,"a");
      
      qApp->postEvent((QObject*)ui->myEdit,(QEvent *)eve1);
      qApp->postEvent((QObject*)ui->myEdit,(QEvent *)eve2);
      

      Regards,
      Mucip:)

      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