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. Can a class derived from QGraphicsWidget override boundingRect()?
Forum Updated to NodeBB v4.3 + New Features

Can a class derived from QGraphicsWidget override boundingRect()?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 956 Views 3 Watching
  • 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.
  • P Offline
    P Offline
    patrcki
    wrote on 11 Apr 2016, 01:40 last edited by patrcki 4 Nov 2016, 01:46
    #1

    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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on 11 Apr 2016, 12:13 last edited by
      #2

      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
      P 1 Reply Last reply 12 Apr 2016, 07:01
      1
      • P Offline
        P Offline
        patrcki
        wrote on 12 Apr 2016, 06:59 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • A Asperamanca
          11 Apr 2016, 12:13

          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
          P Offline
          P Offline
          patrcki
          wrote on 12 Apr 2016, 07:01 last edited by
          #4

          @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.

          1 Reply Last reply
          0

          1/4

          11 Apr 2016, 01:40

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved