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

ItemClipsChildrenToShape has no always effect on children

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.0
    • Fix Version/s: None
    • Component/s: Widgets: GraphicsView
    • Labels:
      None
    • Environment:
      Windows 7 32bit
    • Platform/s:
      Windows

      Description

      I created a inherited class from QGraphicsRectItem. In it it set an QGraphicsSimpleTextItem as child. Then I set the flag

      QGraphicsItem::ItemClipsChildrenToShape

      . When I use hoverMouseEvent (for example) , the clip is not set every time.

      I have to set it always new if a event is triggered.

      #include <QGraphicsRectItem>
      
      QT_BEGIN_NAMESPACE
      class QGraphicsSceneMouseEvent;
      class QParallelAnimationGroup;
      QT_END_NAMESPACE
      
      class MyItem : public QGraphicsRectItem
      {
      public:
          MyItem(QGraphicsItem *parent = nullptr);
          QRectF boundingRect() const override;
          void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;protected:
          QGraphicsSimpleTextItem mDisplayText;    void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;};
      MyItem::MyItem(QGraphicsItem *parent)
          : QGraphicsRectItem(parent),
      mDisplayText(this)
      {
          this->mDisplayText.setPos(5, 5);
          this->mDisplayText.setText(text);    this->setFlag(QGraphicsItem::ItemClipsChildrenToShape); //set for the first time
      }
      
      void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
      {
          QGraphicsRectItem::paint(painter, option, widget);
      }
      
      QRectF MyItem::boundingRect() const
      {
          return this->rect();
      }
      
      void MyItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
      {    
          //this->setFlag(QGraphicsItem::ItemClipsChildrenToShape); // when it's active, it works    
      QGraphicsItem::hoverEnterEvent(event);
      }
      

       

        Attachments

        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:
            anno12 Fritz Becker
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes