Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is a way to don't resize QLabel with QPixmap?



  • Hello,

    I have QGridLayout with 9 QLabels on it. I would like to have the same 9 cell's sizes in this QGridLayout, so I set:

        for(int i=0; i<3;i++)
        {
            grid->setColumnStretch(i,1);
            grid->setRowStretch(i,1);
        }
    

    Now I would like to add QPixmap to one cell ( for example 0,0 ). When I do this I get one big cell (0,0) with QPixmap and 8 smaller.

    What I would like to have:

    whatIwouldLike.png

    What I have now:

    whatIwant.png

    Of course the rest 8 cells are empty.

    When I do the same but with QLabels with no QPixmaps everything is ok.



  • The pixmap will change the size hint of the label.
    Just set size policy of both directions to Ignored



  • @Bonnie Perfect! Thank you!



  • @Bonnie said in Is a way to don't resize QLabel with QPixmap?:

    Just set size policy of both directions to Ignored

    I have been using Qt widget size policies for a long time now, and I still don't always get how they do/do not work! Maybe I should be using Ignored more, which I have never touched...



  • @JonB
    The other values are all related to the size hint.
    So if you don't care about its size hint at all, then you probably should use Ignored.


Log in to reply