I've got a cell in a QTableWidget that holds a number of images. In my delegat for that row I call drawImage.

Qt Code:
  1. void DescriptionDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex & index) const
  2. {
  3. painter->save();
  4. //
  5. // code to calculate the QRect for drawing the image as well as the code to build the image
  6. //
  7. QFrame *aFrame = new QFrame(); // qobject_cast wouldn't deal with QImage
  8. aFrame->setGeometry( iconRect );
  9.  
  10. QImage theImage;
  11. theImage.loadFromData( imageData, "PNG");
  12. painter->drawImage( iconRect, theImage);
  13. painter->restore();
  14. }
To copy to clipboard, switch view to plain text mode 

This works exactly as I desire. The problem comes when I want to display a different tooltip based on which icon the cursor is currently hovering over. I have a class derived from QTableWidgetItem and in my data method I'm trying to figure out where the cursor is (i.e. which QImage) so that I can select the correct string to return. Below is the current Data method. It's pretty sparce because none of my approaches so far have given me information about what's under the cursor.

Can anyone help? Is this possible?

Qt Code:
  1. QVariant ImageItem::data( int role ) const
  2. {
  3. if ( role == Qt::ToolTipRole )
  4. {
  5. QPoint pos = QCursor::pos();
  6. QWidget* curWidget = QApplication::widgetAt( pos );
  7. //
  8. // according to debug information curWidget is a "qt_scrollarea_viewport"
  9. //
  10. QList<QVariant> myData = QTableWidgetItem::data( Qt::ToolTipRole ).toList(); // the list of strings to choose from
  11. //
  12. // note: this method looks at a QFrame because the QImage is not derived from QObject so qobject_cast didn't work
  13. //
  14. QFrame *anImg = qobject_cast<QFrame*> curWidget
  15. if ( anImg )
  16. {
  17. qDebug() << "huzzah. Found it.";
  18. }
  19. else
  20. {
  21. qDebug() << "widget At didn't work :-(";
  22. }
  23. return QVariant("Dummy data because I cannott pick string.");
  24. }
  25.  
  26. return QTableWidgetItem::data( role );
  27. }
To copy to clipboard, switch view to plain text mode 

If there's anything I can clarify let me know. All help is appreciated.