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. QGraphicsItem clip to scene Rect
Forum Updated to NodeBB v4.3 + New Features

QGraphicsItem clip to scene Rect

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 982 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.
  • Y Offline
    Y Offline
    yonnak
    wrote on last edited by
    #1

    Hi,
    I'm trying to clip my items inside the scene rect.
    I have customs items whith the paint method redifined and the following line inside it:

    painter->setClipRect(mapRectFromScene(QRect(0,0,50000,50000))); 
    

    where the rect is my scene rect. If no rotation is applied to the item or if the rotation is 90, 180 or 270 degrees it works well but when I rotate the item by 45° for example (using qtransform) the rect return by mapRectFromScene is not what I expect.

    I have some difficulties understanding transformations and matrix, any help would be appreciated!

    Thanks

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      yonnak
      wrote on last edited by
      #2

      I've solved it like this (in custom item paint method):

          QRectF r = QRectF(0,0,50000,50000).translated(-scenePos());
          QPainterPath p;
          p.addRect(r);
          p = transform().inverted().map(p);
          painter->setClipPath(p);
      
      1 Reply Last reply
      1

      • Login

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