Results 1 to 3 of 3

Thread: Problem with setting a label's maximum size

  1. #1
    Join Date
    Oct 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with setting a label's maximum size

    Hello!

    I'm using a QLabel with a specified QPixmap to show an image in my main window. Whenever I resize the window, I would like that the label stays centered, both horizontally and vertically, but the label's contents (the image) not to be resized. For that I am using both Horizontal and Vertical size policies as Fixed, ScaledContents as false, as MaximumSize as 16777215 x 16777215. This has been working as expected.

    What I would like now ito specify a maximum image size so that if the image loaded is larger than the maximum size, have them scaled to fit this maximum. For that, I tried setting MaximumSize as 500x500, and keep the rest as it is (SizePolicy as (Fixed, Fixed)).

    What happens now, however, is that the label is being stretched both vertically and horizontally when I resize the window, even though it's SizePolicy is Fixed on both directions, and the new MaximumSize is even smaller than the previous one.

    This doesn't seem to make any sense to me. What am I doing wrong?
    Thanks!

  2. #2
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Problem with setting a label's maximum size

    I don't know what is wrong but as a workaround you can try to scale down the pixmap. QPixmap::scaled

  3. #3
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with setting a label's maximum size

    You should use layouts.

Similar Threads

  1. The maximum size of a QList
    By Denarius in forum Newbie
    Replies: 3
    Last Post: 30th November 2012, 10:27
  2. QDialog setting maximum width to content
    By warchild in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2012, 14:08
  3. Get maximum size a widget can get
    By joseprl89 in forum Qt Programming
    Replies: 0
    Last Post: 8th August 2011, 08:57
  4. Replies: 6
    Last Post: 27th July 2010, 21:07
  5. maximum size of xml files
    By freeskydiver in forum Qt Programming
    Replies: 1
    Last Post: 15th January 2008, 10:02

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.