Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainterPath selection problem
QtWS25 Last Chance

QPainterPath selection problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 609 Views
  • 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by CJha
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      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

      CJhaC 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why not use QGraphicsItem::hoverEnterEvent and its friend ?

        CJhaC Offline
        CJhaC Offline
        CJha
        wrote on last edited by
        #3

        @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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved