Hi,

I'm trying to figure out how to find out exactly where the user clicked within cell in a QTableWidget. (I'm using Qt 4.5.2)

I've got a table in a cell with several icons that indicate state (they are QImages drawn in the delegate's paint method). I want the user to be able to click on one of of the icons and have a dialog pop up. I've figured out how to isolate the mouse for displaying a tool tip depending on which icon the mouse is hovering over but I am at a loss as to how to get the information I need to the delegate for a click.

Here's what I am doing right now:

I've connected the cellClicked signal to my slot.

Qt Code:
  1. connect( myTable, SIGNAL( cellClicked(int, int) ), this, SLOT( myCellClicked(int,int)) );
To copy to clipboard, switch view to plain text mode 

Then I gather some information and pass it to the delegate for handling. In the delegate I can calculate the QRect that surrounds the specific icon. Just am not seeing how to properly map the mouse location.

Qt Code:
  1. void myCellClicked( int row, int column )
  2. {
  3. QModelIndex index = myTable->currentIndex();
  4. //
  5. // this QRect is relative to the selected cell. Yay!
  6. //
  7. qDebug() << " if I call visual Rect I get " << myTable->visualRect(index );
  8. QPoint mousePos = QCursor::pos();
  9. QPoint localPos = myTable->mapFromGlobal( mousePos );
  10. qDebug() << " mouse positions global= " << mousePos << "local = " << localPos;
  11. //
  12. // The problem is that localPos seems to be relative to myTable's viewport
  13. // and not specifically to the cell. That's the piece of information I'm trying to find.
  14. //
  15. DetailDelegate *itsDelegate = qobject_cast<lDetailDelegate*>(myTable->itemDelegate( index ) );
  16. itsDelegate->handleClick( index, myTable->visualRect(index), localPos );
  17.  
  18. }
To copy to clipboard, switch view to plain text mode