是否可以从QModelIndex获取Qpoint

Raj*_*war 2 c++ qt

是否可以从QModelIndex获取Qpoint.我想获得一个Qpoint,以便我可以在某一行显示工具提示.

vah*_*cho 6

您可以使用QAbstractItemView::visualRect(const QModelIndex &index)它将返回索引处项目占用的视口上的矩形.例如:

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);
Run Code Online (Sandbox Code Playgroud)