View Full Version : QLabel size policy

Caius Aérobus
6th December 2007, 22:31
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?

class FieldImage : public QLabel

FieldImage::FieldImage(QString legend)
this->setPixmap(QPixmap(10, 10));
this->Print("pixmap size: %d %d", this->pixmap()->size().width(), this->pixmap()->size().height());
this->Print("widget size: %d %d", this->size().width(), this->size().height());

FieldImage: pixmap size: 10 10
FieldImage: widget size: 640 480

6th December 2007, 22:38
Problem 1: the layout handles the widget size and position. Solution: use setFixedSize.
Problem 2: the same as 1, same solution.

Caius Aérobus
7th December 2007, 18:13
Ok, thanks, brutal solution but...effective!

7th December 2007, 18:57
Not brutal. Proper.