Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.0
-
None
-
Windows 7 32bit
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); }