Set Qlabel width
I have used setGeometry() method to set the QLabel width dynamically. I have qlabel in Form Ui.
ui->qlabel->setGeometry(x, y, width, height);
QLabel::setFixedWidth(int)
. Though to make it more flexible (don't have to worry about layouts changing things), I would subclass QWidget
, add slots for the two numbers, and reimplement paintEvent(..)
to draw the two sections.
Hm, i`m just using resize() method. For example my widget, implemented from QLabel:
BenchItem *itm=static_cast<BenchItem*>(widget);
itm->resize(this->width(),itm->height());
i don`t need change height so it uses itself height, but width should change due to parents width().