Why is QLabel wrapping up prematurely?

The following code has enough space for the shortcut to fit on one line, but for some reason it breaks it into two lines after "thats". Why and how to prevent it?

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->setFixedSize(250,100);

    QLabel *label = new QLabel;
    label->setStyleSheet("background-color:blue");
    label->setWordWrap(true);
    label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    label->setText("Oh my gosh thats too funny!");
    label->setParent(this);

}

Again for clarity, this shows:

Oh my gosh thats 
too funny!

I want too:

Oh my gosh thats too funny!
+1
source share
1 answer

Are you using any layout in the widget? If you donโ€™t try to manually set the width and height of QLabels

EDIT:

I wrote code that did not use QLayout, it works fine, quite simply

QLabel *label= new QLabel(QString::fromUtf8("Client code"), this);
label->setGeometry(posx, posy, w, h);

hope this helps

PS: 'this' is my dialogue

class MyDialog : public QDialog 
0
source

Source: https://habr.com/ru/post/1598847/


All Articles