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:
Qt Code:
  1. renderWin = new QWidget() ;
  2. renderWin->installEventFilter(this) ;
  3. QLabel *powered = new QLabel ;
  4. powered->setPixmap(QPixmap(":/images/poweredbyq2.png")) ;
  5. powered->setMaximumSize(512, 512) ;
  6. powered->setScaledContents(true) ;
  7. QHBoxLayout *hl = new QHBoxLayout(renderWin) ;
  8. hl->addSpacerItem(new QSpacerItem(5, 5)) ;
  9. hl->addWidget(powered) ;
  10. hl->addSpacerItem(new QSpacerItem(5, 5)) ;
  11. hl->setStretch(0, 1) ;
  12. // hl->setStretch(1, 1) ;
  13. hl->setStretch(2, 1) ;
  14. hl->setContentsMargins(0, 0, 0, 0) ;
  15. hl->setSpacing(0) ;
To copy to clipboard, switch view to plain text mode 

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