Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    2
    3
    747
    Loading More Posts
    • 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
      hellozee last edited by hellozee

      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 Reply Quote 0
      • A
        Asperamanca last edited by

        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 Reply Quote 4
        • H
          hellozee @Asperamanca last edited by

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post