Hide items in a QBoxLayout

  • Hi,

    I'm running into trouble with a layout problem. I created a layout and inserted there 3 QLabels to show pixmaps.
    The pixmaps are scaled with QT::KeepAspectRatio and showed initialy correct.
    After doubleClick on one of these Labels, the other two are hidden by hide(). The pixmap should be rescaled with the new label size. But this did not happen. Because of the backgroundcolor I know, the label is expanded after finishing the drawing of the pixmap. but not the pixmap. Another double click expands the pixmap to the correct size. How can I get the correct new size of the label in the first round? parentWidget.update() or adjustSize did not work.


  • Hi Erni35.

    The pixmap can't be larger then the height of the label if you use a QHBoxLayout. If you put three labels in a QHboxlayout the width will increase but the height will be the same. With QT::KeepAspectRatio this is exactly the behavior.

    Have you used the following function:
    void QLabel::setScaledContents ( bool )

    If you need to fillout the whole label you need Qt::IgnoreAspectRatio

    @If aspectRatioMode is Qt::IgnoreAspectRatio, the pixmap is scaled to size.@

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.