danny-g
10th October 2012, 16:26
In my program I open a widget and I put a label in it. I want the label to appear in the middle of the widget, so I use a layout. However, when I resize the window, either programmatically with setGeometry or with the mouse, the widget is first resized to the requested size, and then there is an additional size modification. I receive multiple resize events. I tried several QLayout settings, but I haven't find a way to overcome this behavior.
The code of creating the widget is as follows:
renderWin = new QWidget() ;
renderWin->installEventFilter(this) ;
QLabel *powered = new QLabel ;
powered->setPixmap(QPixmap(":/images/poweredbyq2.png")) ;
powered->setMaximumSize(512, 512) ;
powered->setScaledContents(true) ;
QHBoxLayout *hl = new QHBoxLayout(renderWin) ;
hl->addSpacerItem(new QSpacerItem(5, 5)) ;
hl->addWidget(powered) ;
hl->addSpacerItem(new QSpacerItem(5, 5)) ;
hl->setStretch(0, 1) ;
// hl->setStretch(1, 1) ;
hl->setStretch(2, 1) ;
hl->setContentsMargins(0, 0, 0, 0) ;
hl->setSpacing(0) ;
How can I make the layout be resized according to the widget size? It is not a problem of minimal and maximal size, because the new size is always modified, no matter what the new dimensions are.
I will appreciate any advise
The code of creating the widget is as follows:
renderWin = new QWidget() ;
renderWin->installEventFilter(this) ;
QLabel *powered = new QLabel ;
powered->setPixmap(QPixmap(":/images/poweredbyq2.png")) ;
powered->setMaximumSize(512, 512) ;
powered->setScaledContents(true) ;
QHBoxLayout *hl = new QHBoxLayout(renderWin) ;
hl->addSpacerItem(new QSpacerItem(5, 5)) ;
hl->addWidget(powered) ;
hl->addSpacerItem(new QSpacerItem(5, 5)) ;
hl->setStretch(0, 1) ;
// hl->setStretch(1, 1) ;
hl->setStretch(2, 1) ;
hl->setContentsMargins(0, 0, 0, 0) ;
hl->setSpacing(0) ;
How can I make the layout be resized according to the widget size? It is not a problem of minimal and maximal size, because the new size is always modified, no matter what the new dimensions are.
I will appreciate any advise