Is there a way to enable word wrapping of text on some simple widgets like QPushButton?

前端 未结 5 1980
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 05:52

I\'d like to make QPushButton word wrap and expand it\'s height instead of expanding width. How can I do that?

5条回答
  •  温柔的废话
    2020-12-10 06:28

    I have solved the problem with wordwrap on a button this way:

    QPushButton *createQPushButtonWithWordWrap(QWidget *parent, const QString &text)
    {
       auto btn = new QPushButton(parent);
       auto label = new QLabel(text,btn);
       label->setWordWrap(true);
    
       auto layout = new QHBoxLayout(btn);
       layout->addWidget(label,0,Qt::AlignCenter);
    
       return btn;
    }
    

提交回复
热议问题