Results 1 to 4 of 4

Thread: QLabel size policy

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QLabel size policy

    Hello,
    I have two problems with QLabel size.

    First problem: my QLabel contains a 580x580 pixmap but its size is 774x580!
    Additionnal pieces of information are as follows:
    - up to now, it worked on Qt-4.1 under Linux Red Hat 9
    - I have migrated to Mac OS X Leopard with Qt-4.3
    - when I add a print in the paintEvent() slot of the widget I get:
    paintEvent: 580 580 which means the size is ok immediatly after the widget was created!
    paintEvent: 774 580
    paintEvent: 774 580
    paintEvent: 774 580
    ...
    The widget is in a container managed by a QHBoxLayout but I have not put anything else in this container (in order to try to fix this issue).
    Anybody has an idea of what could constraint my QLabel to change its height?



    Second problem:
    I have a QLabel associated with a pixmap but it seems that the QLabel's size is arbitrary set to 640x480, while I would expect that it is adjusted to the pixmap size. Which are the rules to determine the size of the QLabel in this situation?

    Qt Code:
    1. class FieldImage : public QLabel
    2.  
    3. FieldImage::FieldImage(QString legend)
    4. {
    5. this->setPixmap(QPixmap(10, 10));
    6. this->setScaledContents(true);
    7. this->Print("pixmap size: %d %d", this->pixmap()->size().width(), this->pixmap()->size().height());
    8. this->Print("widget size: %d %d", this->size().width(), this->size().height());
    9. }
    10.  
    11. FieldImage: pixmap size: 10 10
    12. FieldImage: widget size: 640 480
    To copy to clipboard, switch view to plain text mode 

  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: QLabel size policy

    Problem 1: the layout handles the widget size and position. Solution: use setFixedSize.
    Problem 2: the same as 1, same solution.

  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLabel size policy

    Ok, thanks, brutal solution but...effective!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLabel size policy

    Not brutal. Proper.

Similar Threads

  1. WordWrap policy for QLabel
    By anju123 in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2007, 22:52
  2. QLabel, large, rich text, font size
    By TheKedge in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2007, 12:56
  3. QScrollView size policy?
    By Henrikas[MI] in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2006, 11:52
  4. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 23:14
  5. QMenuBar size policy
    By krivenok in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2006, 16:13

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.