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. How can I include pen width to QPainterPath (QGraphicsItem Selection Problem)?
QtWS25 Last Chance

How can I include pen width to QPainterPath (QGraphicsItem Selection Problem)?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.2k 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.
  • Y Offline
    Y Offline
    yaseminyilmaz
    wrote on last edited by
    #1

    Hi all,

    I've defined a new class inherited from QGraphicsItem. It's bounding rect has an arrow and curve. It can be easily selected by clicking it's arrow. But it's curve can't. I suppose the reason is corresponding with pen width. Please look at the following code. If I use mBoundingPath in the function checkPointSet, this problem occurs. If I use mRectF, it also has been selected when I click near of the graphic. How can I include pen width to mBoundingPath?

    @
    bool Flow::checkPointSet(QPointF point)
    {
    bool rc = false;

    if (mBoundingPath.contains(point))
    //if (mRectF.contains(point))
    {
        rc = true;
    }
    
    return rc;
    

    }
    void Flow::updateBoundingRect()
    {
    mBoundingPath = QPainterPath();

    addArrow();
    addCurve();
    
    prepareGeometryChange();
    mRectF = mBoundingPath.boundingRect();
    update();
    

    }
    void Flow::addArrow()
    {
    ...
    mArrowHead.clear();
    mArrowHead.append(qLine.p2());
    mArrowHead.append(arrowP1);
    mArrowHead.append(arrowP2);
    mBoundingPath.addPolygon(mArrowHead);
    }
    void Flow::addCurve()
    {
    ...
    mCurvePath = QPainterPath();
    mCurvePath.moveTo(mNodeList[0]->coord());
    mCurvePath.lineTo(mNodeList[1]->coord());

    mBoundingPath.addPath(mCurvePath);
    

    }

    QPainterPath Flow::shape() const
    {
    QPainterPath path;
    path.addRect(mRectF);

    return path;
    }

    QRectF Flow::boundingRect() const
    {
    return mRectF;
    }@

    Thanks in advance for your helps,

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rems
      wrote on last edited by
      #2

      To include the pen width in your bounding shape, you can use QPainterPathStroker:

      @QPainterPathStroker stroker;
      stroker.setWidth(w);
      mBoundingPath = stroker.createStroke(mCurvePath);@

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yaseminyilmaz
        wrote on last edited by
        #3

        Thanks so much to you.

        It has worked with your help. Thanks a lot again.

        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