Can a class derived from QGraphicsWidget override boundingRect()?



  • We have a class that is derived from QGraphicsWidget that overrides boundingRect(). This seems a little counter-intuitive to me given that boundingRect() (which is a pure virtual function of QGraphicsItem) is already implemented by QGraphicsWidget. I'm keen to know if this aligns to best practices as the QGraphicsWidget docs aren't very clear on this.

    A few more details about our class implementation:

    • boundingRect() has been overridden to return the collision geometry.
    • resize() is being called such that rect() returns a RectF that represents the actual model data (the are we paint). This can be smaller than the collision geometry -- we force the object to have a minimum collision size in the boundingRect() function.

    Is this an ill-advised setup? Are there any repercussions for doing this?



  • Question is why you use QGraphicsWidget at all, instead of QGraphicsItem or QGraphicsObject?

    In my book, there are three main reasons to use QGraphicsWidget:

    • I want to use QGraphicsLayouts
    • I want something with a geometry I can explicitly set, instead of having to write my own logic for that.
    • I am lazy and don't want to reimplement boundingRect and paint


  • This post is deleted!


  • @Asperamanca Thanks for the reply, that makes total sense! We'll look to rectify this bit of code -- it's functional as is but doesn't seem like good practice.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.