Qitemdelegate signal / slot
i have a qitemdelegate on a qtreeview. When the user moves with the cources over a position in a qitemdelegate, i will open a popup window.
How can i check the position in a qitemdelegate??
You should reimplement virtual bool editorEvent( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ) in your delegate. It will get called with mouse events I think. If not, you might need to enable mouse tracking on the widget.
Thnaks, it works!
How can i get in the editorEvent the mouse Position relative to the delegate field?
option.rect.x() returns the position relative to my monitor...
You might be able to use QWidget::mapFromGlobal for that task.
Ok, i need the x & y coordinate relative to the view..
In the editorEvent, how can i get the QTreeView Object?
I have a Delegate, in which i overloaded the paint method, and the editorEvent.
In the paint method, i draw some points, and i get the position of the x,y with the following code:
@ int x = option.rect.x();
int y = option.rect.y();@
When the mouse is over the point, i will execute some actions, so the painted point must have in the editorEvent the same coordinates as in the point method.
@ QMouseEvent mouseEvent = static_cast<QMouseEvent>(event);
qDebug() << mouseEvent->x() << mouseEvent->y();@
returns in the editorEvent the correct positions, thanks :)!
Please just edit your previous post instead of posting three messages in a row...
What I'd do, is make your delegates constructor so that it takes a pointer to a QAbstractItemView. That way, you always have a pointer to the widget the delegate is used for. This is not a hack, as the documentation for delegates already warns about re-using the same delegate for multiple views. So, they are already "bound" to a specific view anyway.