Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    [SOLVED] How to convert and to forward a tap-and-hold gesture to QGraphicsTextItem to activate link

    Mobile and Embedded
    1
    2
    1091
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Gianluca
      Gianluca last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • Gianluca
        Gianluca last edited by

        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 );
        }
        @

        1 Reply Last reply Reply Quote 0
        • First post
          Last post