Results 1 to 11 of 11

Thread: get qgraphicsitem size

  1. #1
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default get qgraphicsitem size

    after changing the size of an item, how can i get the new size ?

    trackItem is a QGrapicsItem.


    Qt Code:
    1. if (ui->heightButton->isChecked()==false)
    2. {scene->trackItem->scale(1 ,1.1);}
    3. else
    4. {scene->trackItem->scale(1,.90);}
    5. newSize = scene->trackItem->sceneBoundingRect(); <- this is where i am trying to get the new size of the item.
    6.  
    7. // boundingrect does not change even after rescaling.
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get qgraphicsitem size

    How do you change the size of the item ? The size is always mentioned in boundingRect() or shape().
    If you are using some variable to change the size, then you must have the size with you. Hope am getting it correct

  3. #3
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: get qgraphicsitem size

    I am changing it with

    if (ui->heightButton->isChecked()==false)
    {scene->trackItem->scale(1 ,1.1);}
    else
    {scene->trackItem->scale(1,.90);}

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get qgraphicsitem size

    The bounding rect will be same. What happens is the transform of the item is changed, and the item is drawn accordingly.
    May be if you tell what you want to achieve, we can tell more clearly.

    For now it seems you have a look at transform() function of the QGraphicsItem

  5. #5
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: get qgraphicsitem size

    after i change the size of the item, i want to know the new size

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: get qgraphicsitem size

    Just calculate the new size:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QGraphicsTextItem *item = scene.addText("foo");
    8. view.setScene(&scene);
    9. view.show();
    10.  
    11. qWarning() << item->boundingRect().size() << item->scale() << item->boundingRect().size() * item->scale();
    12. item->setScale(11.91);
    13. qWarning() << item->boundingRect().size() << item->scale() << item->boundingRect().size() * item->scale();
    14.  
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get qgraphicsitem size

    I dont think there is a function QGraphicsItem::scale(void) . It simple scales the item but doesnt return anything.
    You will need to use QGraphicsItem::transform() and use the matrix variables m11,m22 to multiply with the boundingRect.
    Read Basic Matrix Operations

  8. The following user says thank you to aamer4yu for this useful post:

    rogerholmes (18th February 2010)

  9. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: get qgraphicsitem size

    Quote Originally Posted by aamer4yu View Post
    I dont think there is a function QGraphicsItem::scale(void)
    QGraphicsItem::scale()? (added in 4.6)

    Returns
    txt Code:
    1. QSizeF(30, 25) 1 QSizeF(30, 25)
    2. QSizeF(30, 25) 1.91 QSizeF(57.3, 47.75)
    To copy to clipboard, switch view to plain text mode 

  10. The following user says thank you to Lykurg for this useful post:

    rogerholmes (18th February 2010)

  11. #9
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Cool Re: get qgraphicsitem size

    Thank You for your help
    I will try this tonite.

  12. #10
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: get qgraphicsitem size

    aamer4yu
    lykurg
    Thank You guys !

    QGraphicsItem::transform() m11,m22 works !

  13. #11
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get qgraphicsitem size

    QGraphicsItem::scale()? (added in 4.6)
    Yeah, u right. Usually at office I have 4.5 assistant open

Similar Threads

  1. QGraphicsItem subclass access to QGraphicsView size
    By rubenvb in forum Qt Programming
    Replies: 4
    Last Post: 23rd January 2010, 21:36
  2. Scale size of QGraphicsItem without scaling pen width
    By Lodorot in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2009, 00:18
  3. Replies: 2
    Last Post: 23rd March 2009, 17:26
  4. Casting QGraphicsItem child from QGraphicsItem
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2008, 15:37
  5. Replies: 2
    Last Post: 28th June 2008, 16:31

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
  •  
Qt is a trademark of The Qt Company.