c++ - 如何在 QPushButton 中自动调整文本?

标签 c++ qt button qpushbutton

我有以下按钮

ui->setMaximumWidth(121);
ui->setMinimumWidth(121);
ui->setMaximumHeight(80);
ui->setMinimumHeight(80);
ui->pushButton->setStyleSheet   ("background-color: QLinearGradient(spread:pad x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.0" + "#e5e4e2" + ",  stop: 0.4" + "#c0beb9" + ", stop: 1.0"+ "#e5e4e2"+");"
                                            "color: #868479; "
                                            "border-style: solid;"
                                            "border-style: solid;"
                                            "border-radius: 7;"
                                            "padding: 3px;"
                                            "padding-left: 5px;"
                                            "padding-right: 5px;"
                                            "border-color: #339;"
                                            "border-width: 1px;"
                                            "font:Bold;"
                                            "font-family:Georgia");

ui->pushButton->setText("Administración de Empresas");

但是“Administración de Empresas”这个词太长了,我看不到完整的短语。

Ps:我不想手动做,我希望我的应用程序检测大短语并自动调整

最佳答案

它应该自动适应按钮的文本。

确保以正确的方式使用 QLayout。

如果您在代码中手动设置尺寸,您可以使用 sizeHint 属性来获取正确的尺寸:

button->resize(button->sizeHint().width(), button->sizeHint().height());

Screenshot

关于c++ - 如何在 QPushButton 中自动调整文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45475140/

相关文章:

c++ - 如何保护具有非常量方法的全局对象

c++ - 字符数组的初始值设定项字符串太长错误

c++ - Qt : send AT command to GPRS modem

python - 如何查找信号是否连接到任何东西

html - 覆盖按钮上的 Bootstrap 事件/访问类

c# - Visual Studios 表单应用程序中的按钮

c++ - 我如何在C++中输入和输出各种文件类型

c++ - 谁能帮我弄清楚为什么我的 lValue 总是出错

c++ - QScrollArea - 有很多 child 的小部件的滚动条

javascript - 我无法用 javascript 做一个简单的计算器