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

ItemClipsChildrenToShape has no always effect on children

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.0
    • Widgets: GraphicsView
    • None
    • Windows 7 32bit
    • 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

            bibr Andreas Aardal Hanssen
            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