[Solved] ItemViews items Focus change signal ?

  • For the ItemsViews (ListView, TreeView, TableView) is there any signal that is emitted when the focus on the items are changed using keys up and down.


  • I don't think there are signals specifically for changes of the current item due to keypresses.

  • Do i need to handle eventFilters and then emit signals?

    The scenario if there are 20 rows in an itemView and if use key up/down the focus of the item changes, How to get the QModelindex of the item that has focus ?

  • Why does it matter how the item gets it's focus?

  • In each row there is a customWidget (with labels,lineEdit etc) that is added using setIndexWidget, So i select the currentIndex and use TAB , the tab order works fine , but if i change to focus of the items using key up/down and then use TAB , the tab changes for the the previous selected items and not the currentItem that has the focus.

    so i though if i can get the modelIndex of the item that has focus then i can setFocus for the widget in that index.

    Edit : I installed an eventFiler for my itemView
    @bool MyItemView::eventFilter(QObject *target, QEvent *event)
    if (target == this && event->type() == QEvent::KeyPress)
    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    if (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down )
    CustomWidget *widget= dynamic_cast<CustomWidget *>(indexWidget(currentIndex()));
    if (widget!=NULL)
    //do something
    return QWidget::eventFilter(target,event);

    return QWidget::eventFilter(target,event);


    This thing works, what should i change so that my current widget accepts TAB order.

  • How to handle shift + tab in key press inside eventFilter >

Log in to reply

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