为什么QLabel过早包装? [英] Why does QLabel prematurely wrap?

查看:128
本文介绍了为什么QLabel过早包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,有足够的空间让标签适合一行,但由于某种原因,它会将其分割为'thats'后面的两行。为什么以及如何防止这种情况?

In the following code there is clearly enough space for the label to fit on one line, but for some reason it splits it into two lines after 'thats'. Why and how do I prevent this?

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, it shows:

Oh my gosh thats 
too funny!



And I want:

Oh my gosh thats too funny!


推荐答案

你在Widget中使用任何布局?如果不尝试手动设置QLabels的宽度和高度

Are you using any layout in the Widget ? If not try setting QLabels width and height manually

编辑:

我写了一个代码, QLayout,它工作正常,很简单

I wrote a code that was not using any QLayout, it works fine, quite simple

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

希望这有助于

this'is my Dialog

PS: 'this' is my Dialog

class MyDialog : public QDialog 

这篇关于为什么QLabel过早包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆