Results 1 to 2 of 2

Thread: Updating the width/height of a QGraphicsItem

  1. #1
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Updating the width/height of a QGraphicsItem

    I'm trying to update the width and height of a QGraphicsItem. I've added QGraphicsItem* testItem to a graphics scene using the addItem function.

    The documentation says I can use the update function to change the width and height, but the item doesn't change.

    Qt Code:
    1. int newWidth = /* something */;
    2. int newHeight = /* something */;
    3. QRectF newRect = QRectF(testItem->x(), testItem->y(), newWidth, newHeight);
    4. testItem->update(newRect);
    5.  
    6. msg1.setText("Update successful? " + QString((testItem->boundingRect().width() == width) ? "true" : "false") + QString("\n\nRequested size: ") + QString::number(newWidth) + " x " + QString::number(newHeight) + "\nActual size: " + QString::number(testItem->boundingRect().width()) + " x " + QString::number(testItem->boundingRect().height()));
    7. msg1.exec();
    To copy to clipboard, switch view to plain text mode 



    Why isn't it updating correctly?

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating the width/height of a QGraphicsItem

    You misunderstood the rect parameter to the update function. With it you can specify a sub-rectangle that needs updating. In contrast to updating the whole item with update().

    Look into QGraphicsWidget to have an item with a size. Otherwise you need to store your own geometry data and report it back through the boundingRect() function.

    HIH

    Joh

Similar Threads

  1. Fix proportion of width and height in QGridLayout
    By Wong in forum Qt Programming
    Replies: 6
    Last Post: 7th January 2011, 07:24
  2. Replies: 3
    Last Post: 13th May 2010, 08:20
  3. how to increase menuitem's height and width?
    By aoo7wangyan in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2009, 10:00
  4. Pixmap height / width without loading it
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 07:10
  5. width and height of QTabWidget
    By chikkireddi in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 13:53

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.