Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-83644

QGraphicsPathItem generates shape incorrectly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.14.2
    • Fix Version/s: None
    • Component/s: Widgets: GraphicsView
    • Labels:
      None
    • Environment:
      Arch Linux 64 bit
    • Platform/s:
      Linux/X11

      Description

      Hello everyone, this is my first issue report - if something isn't up to standard please let me know!

      I am currently trying to setup a QGraphicsView with hoverable quadratic curves.
      For this purpose I subclassed `QGraphicsPathItem` and implemented the `hoverEnterEvent` and `hoverLeaveEvent` methods as follows (I'm aware this isn't the ideal way to achieve a colouring effect on hover):

      void connection_graphics_item::hoverEnterEvent(QGraphicsSceneHoverEvent* event) {
          QGraphicsItem::hoverEnterEvent(event);    
          QPen pen;
          pen.setWidth(4.0f);
          pen.setColor(Qt::yellow);    
          setPen(pen);
      }
      void connection_graphics_item::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) {
          QGraphicsItem::hoverLeaveEvent(event);    
          QPen pen;
          pen.setWidth(4.0f);
          pen.setColor(Qt::black);    
          setPen(pen);
      }
      

      Doing this I noticed that the hover detection was off, from one side it would be fine, from the other side it would detect it far outside its visual bounds.

      I looked a bit at the source of the `shape` function implementation and spotted this:
      <https://code.woboq.org/qt5/qtbase/src/widgets/graphicsview/qgraphicsitem.cpp.html#881>

      After reimplementing the function and using the same code - minus that last line, the hover detection for my quadratic curves worked flawless. I'm not sure if that last call can just be removed, as the function is used by other components as well, but it at least fixed it for `QGraphicsPathItem` for me.

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              bibr Andreas Aardal Hanssen
              Reporter:
              folling Jonathan Purol
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes