Results 1 to 2 of 2

Thread: QGraphicsSvgItem sizing

  1. #1
    Join Date
    Jun 2007
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsSvgItem sizing

    I have a class derived from QGraphicsSvgItem where I implement boundingRect as a function of the sceneRect()'s width and height. I want the SVG graphic to scale to fill the boundingRect, but I can't seem to get the trick. How could I cause the SVG graphic (which is smaller than the boundingRect) to fill the boundingRect (keeping its original aspect)?

    I know you can scale() it, but I'm not sure how I'd discover how *much* to scale it, if that's even the right approach.

    Thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsSvgItem sizing

    I am not sure if it is possible to always keep the aspect ratio after scaling.
    If the aspect ratio of the scene rect is not equal with the aspect ratio of item's bounding box, then you're out of luck.

    Generally, the scale factors are as follows:
    Qt Code:
    1. float sx = sceneRect.width()/boundingBox.width();
    2. float sy = sceneRect.height()/boundingBox.height();
    To copy to clipboard, switch view to plain text mode 

    Next, you must call:
    Qt Code:
    1. svgItem->scale( sx, sy );
    To copy to clipboard, switch view to plain text mode 

    There might be needed a repositioning( to center the item in view), but only in practice you can see if it is really necessary.

    If the aspect ratios don't match, and if you find it acceptable, you can pad the item with a certain color or pattern in the area where it does not fill the scene rect.

    Regards

Similar Threads

  1. Delegate editor sizing problem
    By smacchia in forum Qt Programming
    Replies: 19
    Last Post: 7th December 2007, 16:27
  2. [solved] Problems with QGraphicsSvgItem
    By grosem in forum Newbie
    Replies: 4
    Last Post: 17th June 2007, 18:27
  3. Border cutting with QGraphicsSvgItem
    By akiross in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 09:12
  4. Sizing problem
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 7
    Last Post: 2nd April 2007, 17:31
  5. Automatic sizing of QTableWidget's cells
    By Artem Anisimov in forum Qt Programming
    Replies: 2
    Last Post: 4th September 2006, 19:01

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.