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. What is best approach to not draw items outside the QGraphicsView?

What is best approach to not draw items outside the QGraphicsView?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.1k Views
  • 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.
  • H Offline
    H Offline
    hellozee
    wrote on last edited by hellozee
    #1

    I have implemented both QGraphicsView and QGraphicsScene.

    I wanted to not draw the part of the QGraphicsItem which is outside the screen rectangle.

    I wanted something like this:
    expected

    But currently I am getting this:
    current

    In short, according the above couple of photos, I wanted the red rectangle to not to be drawn outside the screen rectangle which is determined by the White Rectangle at the time of initialization.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      You can make all your items children of a single custom QGraphicsItem or QGraphicsWidget, which is the only item directly inserted in the scene. If you set the flag ItemClipsChildrenToShape, no item will draw beyond the boundingRect of that parent item. Then, you need to keep the size of the item up-to-date if your visible area changes.

      H 1 Reply Last reply
      4
      • A Asperamanca

        You can make all your items children of a single custom QGraphicsItem or QGraphicsWidget, which is the only item directly inserted in the scene. If you set the flag ItemClipsChildrenToShape, no item will draw beyond the boundingRect of that parent item. Then, you need to keep the size of the item up-to-date if your visible area changes.

        H Offline
        H Offline
        hellozee
        wrote on last edited by
        #3

        @Asperamanca Thanks, it is working the way I wanted.

        1 Reply Last reply
        0

        • Login

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