[SOLVED] How to convert and to forward a tap-and-hold gesture to QGraphicsTextItem to activate link
-
Dear all,
I have a QGraphicsTextItem inside a custom QGraphicsObject.
The custom QGraphicsObject grab various gesture in order to do various things.
But when a TapAndHold gesture has been recognized I want to check is at that point on the underlying QGraphicsTextItem there is an hyperlink and active it (openUrl).How can I do that ?? Any suggestions ??
My first idea was to create a QGraphicsSceneMouseEvent with the information with TapAndHold gesture and send it to QGraphicsTextItem... but I failed becaouse there is no constructor for creating a QGraphicsSceneMouseEvent.
Any other options ??
Is there a way to check and to extract the hyperlink from QGraphicsTextItem without event ??Thanks,
Gianluca. -
I solved the problem.
The solution is to get the QAbstractDocumentLayout from the QTextDocument returned by QGraphicsTextItem::document.With the QAbstractDocumentLayout there are various method to check the content under a point. One of them is anchorAt.
So, in the handler for TapAndHold the following lines of code do the work:
@ QString mayUrl = contacts->document()->documentLayout()->anchorAt( contacts->mapFromScene(tap->position()) );
if ( !mayUrl.isEmpty() ) {
qDebug() << "TRY TO OPEN" << mayUrl;
QDesktopServices::openUrl( mayUrl );
}
@