Results 1 to 1 of 1

Thread: Incorrect selection rect of QGraphicsItemGroups containing offset QGraphicsPixmapItem

  1. #1
    Join Date
    Feb 2008
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Incorrect selection rect of QGraphicsItemGroups containing offset QGraphicsPixmap

    I'm adding QGraphicPixmapItems to a QGraphicsItemGroup and I've encountered a problem: if I apply an offset to the pixmap items (via QGraphicPixmapItem::setOffset()), the selection rectangle for the group doesn't reflect that offset (i.e., the group's selection rectangle remains the bounding rectangle of all the pixmap items without any offset applied). Here's a (simplified) code snippet showing how in my class that's derived from QGraphicsItemGroup I add a pixmap item to the group:
    Qt Code:
    1. void MyGraphicsItemGroup::addPixmapItem( const QPixmap& pixmap )
    2. {
    3. QPointF offset = QPointF( -pixmap.width() / 2, -pixmap.height() / 2 );
    4.  
    5. this->addToGroup( gpi );
    6. gpi->setOffset( offset );
    7.  
    8. /// ... do other stuff
    9. }
    To copy to clipboard, switch view to plain text mode 

    I tried subclassing QGraphicsItemGroup and reimplementing boundingRect() so that it takes the offsets into account, but that didn't work (the selection rect was the same as before), leading me to believe that QGraphicsItemGroup must use some other function to figure out what the bounding rect of its items are for purposes of drawing the selection rectangle. It seems like childrenBoundingRect() might be a candidate, but it's not a virtual function, so I can't override its behavior. Does anyone know if what I'm trying to do is even possible? Any help or insights greatly appreciated!

    BTW, I'm using Qt 4.5 + MSVC 2005/gcc 4.1.


    Added after 34 minutes:


    So, it turns out that calling setOffset() *before* adding the item to the group solves the problem. Yay for me!
    Last edited by kerchen; 9th June 2011 at 18:49.

Similar Threads

  1. Timezone offset
    By pdoria in forum Qt Programming
    Replies: 5
    Last Post: 7th February 2014, 05:54
  2. Incorrect option.rect in custom item delegate
    By Jarvis in forum Qt Programming
    Replies: 0
    Last Post: 16th April 2010, 23:48
  3. QGraphicsItem and the selection rect
    By Markus in forum Qt Programming
    Replies: 0
    Last Post: 9th February 2010, 22:21
  4. LIMIT and OFFSET for QSqlRelationalTableModel
    By mkarakaplan in forum Newbie
    Replies: 8
    Last Post: 6th November 2007, 00:06
  5. QTableWidget, row offset
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2006, 11:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.