Search code examples
c++qtheightqwidget

How to prevent a custom QWidget from being resized?


I've created a custom QWidget in Qt , in the application , a few instances are created and added to a QVBoxLayout. the problem is: i need the widgets to all remain at a height of 100 pixels. What happens is that the layout seems to be giving each widget an equal portion of the entire window. How do i prevent this?


Solution

  • You can set a fixed height for your widget :

    myWidget->setFixedHeight(100);
    

    You can also set a maximum height if you don't want it to have more than a specific height :

    myWidget->setMaximumHeight(100);