Rajeshwar
Rajeshwar

Reputation: 11651

Is it possible to get Qpoint from QModelIndex

Is it possible to get a Qpoint from a QModelIndex. I would like to get a Qpoint so that I could display a tooltip at a certain row.

Upvotes: 2

Views: 1458

Answers (2)

Pavel Strakhov
Pavel Strakhov

Reputation: 40502

You should implement your model so that it returns tooltip contents when Qt::ToolTipRole role is requested. This is a proper model-view way to add tooltips to views.

Upvotes: 2

vahancho
vahancho

Reputation: 21220

You can use the QAbstractItemView::visualRect(const QModelIndex &index) that will return the rectangle on the viewport occupied by the item at index. For example:

QRect rect = tableView->visualRect(index); // index is a QModelIndex
QPoint pos = tableView->mapToGlobal(rect.center());
QToolTip::showText(pos, "This is my tool tip", tableView, rect);

Upvotes: 6

Related Questions