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.
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);
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.