Thank you wysota.
I tried overriding QTableView::event(QEvent *event) but I don't get QEvent::ToolTip events when hovering over individual cells, just when hovering over areas of the table view with no cells or headers.
I tried overrding viewportEvent() instead and this allows me to only show tooltips for items whose text is elided. However, the tooltip does not go away if I then hover over an item whose text is not elided. It seems that eating this event is preventing the tooltip from being cleared.
Do you have any suggestions on how to resolve this?
Here is the code:
bool MyWidget
::viewportEvent(QEvent *event
) { if (event
->type
() == QEvent::ToolTip) { QHelpEvent *helpEvent
= static_cast<QHelpEvent
*>
(event
);
if (index.isValid()) {
QSize sizeHint
= itemDelegate
(index
)->sizeHint
(viewOptions
(), index
);
QRect rItem
(0,
0, sizeHint.
width(), sizeHint.
height());
QRect rVisual
= visualRect
(index
);
if (rItem.width() <= rVisual.width())
return false;
}
}
}
bool MyWidget::viewportEvent(QEvent *event) {
if (event->type() == QEvent::ToolTip) {
QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event);
QModelIndex index = indexAt(helpEvent->pos());
if (index.isValid()) {
QSize sizeHint = itemDelegate(index)->sizeHint(viewOptions(), index);
QRect rItem(0, 0, sizeHint.width(), sizeHint.height());
QRect rVisual = visualRect(index);
if (rItem.width() <= rVisual.width())
return false;
}
}
return QTableView::viewportEvent(event);
}
To copy to clipboard, switch view to plain text mode
Bookmarks