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. CellExited()
Qt 6.11 is out! See what's new in the release blog

CellExited()

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.8k 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.
  • _ Offline
    _ Offline
    _Mark_
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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().

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • _ Offline
        _ Offline
        _Mark_
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          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;
          }
          @

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • _ Offline
            _ Offline
            _Mark_
            wrote on last edited by
            #5

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

            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