¿Es posible obtener Qpoint de 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.

preguntado el 27 de noviembre de 13 a las 07:11

2 Respuestas

Puede utilizar el 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);

respondido 27 nov., 13:07

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.

respondido 27 nov., 13:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.