Qt Forum

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

    Unsolved QPainterPath selection problem

    General and Desktop
    2
    3
    260
    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.
    • CJha
      CJha last edited by CJha

      Hi! I am trying to plot a line plot in QWidget or in QGraphicsView. I am using QPainterPath to draw my line plot in both, and I am trying to have an ability to select the given Path by either clicking on it or highlight the path when the mouse hovers over it. I am doing this in QWidget using bool QPainterPath::intersects(const QRectF &rectangle) const function and in QGraphicsView using void QGraphicsScene::focusItemChanged() Signal. With QWidget I can detect the mouse hover and with QGraphicsView I can detect mouse press.

      I only want to detect a mouse hover or mouse pressed when my cursor is right over the QPainterPath but it is being triggered even when the cursor is in the red region in the below image (the black thick line is my QPainterPath).

      QGraphicsProblem.PNG

      It appears that this is happening because Qt considers the area enclosed by the path as being part of QPainterPath. I also checked by drawing my line plot with QPolygonF, it has the same result as QPainterPath. (I do not understand Qt's thinking in this regard, an open path is a group of small line segments joined together end-to-end, not an area). Is there any way around it? All I want to do is to find out when my mouse is over my path.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by SGaist

        Hi,

        Why not use QGraphicsItem::hoverEnterEvent and its friend ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        CJha 1 Reply Last reply Reply Quote 0
        • CJha
          CJha @SGaist last edited by

          @SGaist I tried using that but it requires the calculation of boundingRect() beforehand and implementing it in QGraphicsScene by calling prepareGeometryChange() to allow QGraphicsScene to update its bookkeeping. This will result in an extra calculation burden which I am trying to avoid, I will use it if I have no other option.
          I tried to solve this problem by using a "kind of" boundary for my curve by drawing curves above and below my actual curve and to detect QPainterPath::intersects() for both of them. This would give me an XOR logic to detect the mouse hover event. So my curves look like this:

          PainterPathProb_2.PNG

          With green one being the lower curve and red one being the upper curve. But when I draw the QPainterPath the enclosed area becomes something like this:

          PainterPathProb_3.PNG

          Where red is the enclosed area of the upper curve and green is the enclosed area of the lower curve. These enclosed areas make no sense to me, what kind of a mathematical formula will result in 3 sine waves varying just in their base amplitude (i.e. only their zeros lie at different y values) will result in an enclosed area like that.

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