QLabel *label = new QLabel("This is a label"); label->setMaximumHeight(50); // set maximum height to 50 pixels
QLabel *label = new QLabel("This is a label"); label->setMaximumHeight(parentWidget->height() / 2); // set maximum height to half of parent widget heightIn this example, we create a new QLabel and set its maximum height based on the height of its parent widget. We divide the parent's height by 2 to set the maximum height to half of the parent widget height. Package library: Qt. The QLabel class is part of the Qt framework and is included in the QtWidgets library.