Results 1 to 5 of 5

Thread: fit image size to frame

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default fit image size to frame

    when the image is loaded in the frame, I need to resize frame to fit image size. Otherwise image margins may get out of frame border.
    can I resize the whole image generally to fit exactly inside a frame of any size ? the image is png

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: fit image size to frame

    Hi,

    Take a look at QImage::scaled
    Òscar Llarch i Galán

  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: fit image size to frame

    Quote Originally Posted by ^NyAw^ View Post
    Hi,

    Take a look at QImage::scaled
    I used scaled() to resize the image, but it has no effect!

    Qt Code:
    1. QImage myImage;
    2. myImage.load("path-to-png");
    3. myImage.scaled(ui->frame->width(), ui->frame->height(), Qt::IgnoreAspectRatio );
    4. ui->frame->setPixmap(QPixmap::fromImage(myImage));
    To copy to clipboard, switch view to plain text mode 

    is there anything wrong with the code?

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: fit image size to frame

    Hi,

    is there anything wrong with the code?
    Yes.
    It's a programming error. Have you looked what the method does? Or what it says that does?
    Returns a copy of the image scaled to a rectangle with the given width and height according to the given aspectRatioMode and transformMode.
    Òscar Llarch i Galán

  5. #5
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: fit image size to frame

    thanks for the hint.

Similar Threads

  1. Replies: 4
    Last Post: 19th August 2011, 09:13
  2. How to get video frame size
    By mrudula in forum Qt Programming
    Replies: 4
    Last Post: 21st April 2011, 13:39
  3. Finding frame size of the video file
    By mrudula in forum Qt Programming
    Replies: 0
    Last Post: 16th August 2010, 12:26
  4. Image without window frame?
    By niky in forum Qt Programming
    Replies: 6
    Last Post: 3rd February 2008, 09:37
  5. howto expand frame to maximum size
    By masoroso in forum Newbie
    Replies: 4
    Last Post: 21st April 2006, 09:40

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.