有没有办法在一些简单的小部件(如 QPushButton)上启用文本自动换行? [英] Is there a way to enable word wrapping of text on some simple widgets like QPushButton?

查看:84
本文介绍了有没有办法在一些简单的小部件(如 QPushButton)上启用文本自动换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让 QPushButton 自动换行并扩展它的高度而不是扩展宽度.我该怎么做?

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

推荐答案

我已经通过这种方式解决了按钮上自动换行的问题:

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;
}

这篇关于有没有办法在一些简单的小部件(如 QPushButton)上启用文本自动换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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