Results 1 to 2 of 2

Thread: Centering a scaled image

  1. #1
    Join Date
    May 2014
    Posts
    13
    Qt products
    Qt5
    Platforms
    Windows

    Default Centering a scaled image

    I have two questions.

    First I am displaying a scaled image in a QLabel object on the Ui. Is it more efficient to scale the QImage before transforming into the QPixmap or is it more efficient to convert it into the QPixmap and then scaling it?

    Second I am using the KeepAspectRationByExpanding option. This displays the image from the top, left which means the center of the image may potentially fall outside of the label. Is there an easy way to change it to display the center of the image at the physical center of the label and let the outsides of the image be truncated?

    I'm trying to avoid getting into writing my own paint routine for this, I've never tried that and don't have much time to learn the basics of custom paint functions. Is there another way?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Centering a scaled image

    Quote Originally Posted by gpuckett View Post
    First I am displaying a scaled image in a QLabel object on the Ui. Is it more efficient to scale the QImage before transforming into the QPixmap or is it more efficient to convert it into the QPixmap and then scaling it?
    Might depend on the platform but my guess is that scaling the QImage is better.
    I remember that at least at some point scaling a pixmap meant that it was transferred into a QImage internally, then scaled, then c

    Quote Originally Posted by gpuckett View Post
    Second I am using the KeepAspectRationByExpanding option. This displays the image from the top, left which means the center of the image may potentially fall outside of the label. Is there an easy way to change it to display the center of the image at the physical center of the label and let the outsides of the image be truncated?
    Create a QRect that has the size of the visible area.
    Scale the image and get its rect(), take that rect's center() and move the first rectangle's center to that point.
    Then use this modified rect on the scaled image's copy() and thus get the section you want to display.

    Cheers,
    _

Similar Threads

  1. Vertical centering of a QTextEdit
    By miwarre in forum Newbie
    Replies: 4
    Last Post: 5th October 2015, 06:01
  2. Display full scaled image on a QLabel
    By dcole in forum Qt Programming
    Replies: 2
    Last Post: 10th October 2013, 22:49
  3. displaying scaled image
    By deck99 in forum Qt Programming
    Replies: 5
    Last Post: 18th March 2011, 10:32
  4. Centering a window
    By dwarnold45 in forum Newbie
    Replies: 1
    Last Post: 30th March 2010, 08:43
  5. Replies: 0
    Last Post: 6th April 2009, 02:20

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.