CellExited()



  • Hello,
    I know there are the following signals for a QTableWidget:

    @
    void QTableWidget::cellEntered(int row, int column)
    void QTableWidget::currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
    @

    The first is called when the mouse enter in a cell (no need to click is the tracking is enabled).
    The second is called when a cell receive the focus.

    I need to take an action when the mouse enter a cell (without click) and take another one when it leaves it.
    It seems there isn't a cellLeaved(int row, int column) and I can't use the currentCellChanged() without clicking each cell.

    Any idea about this?
    Mark


  • Moderators

    what are you exactly trying to achieve?

    Basically a cell is left when another cell is entered or on the leave event (leaving the whole table).

    you can also listen for the mouse move event on the viewport (also requires mouse tracking turned on) and check the cell with QAbstractItemView::indexAt().



  • Thanks for your reply.
    I'm trying to achieve exactly what I said :-) I want to take an action when the mouse enter a cell (already done) and another when it leaves.

    Just an example: think to move the mouse over a QTableView and to highlight the cell under the pointer.

    I would highlight the current cell and restore the previous background when the pointer leaves it.


  • Moderators

    ok then you can go with my suggested method. Something like this:
    @
    QPersistenModelIndex index;
    ...
    bool eventFilter(QObject* obj, QEvent* event)
    {
    if( obj == table->viewport() )
    {
    switch( event->type() )
    {
    case QEvent::Leave:
    {
    doStuffWithOldCell(index);
    index = QModelIndex();
    }
    break;
    case QEvent::MouseMove:
    {
    QMouseEvent* e = static_cast<QMouseEvent*>(event);
    QModelIndex newIndex = table->indexAt(e->pos());
    if( index != newIndex )
    {
    doStuffWithOldCell(index);
    index = newIndex;
    doStuffWithNewCell(index);
    }
    }
    break;
    }
    return false;
    }
    @



  • Thanks! Good hint, I'm going to try it!


Log in to reply
 

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