1

我用下面的代码测试:

QProgressDialog* dialog = new QProgressDialog("Message", "Close", 0, 10);
dialog->setWindowTitle("Long Long Long Long Title");
dialog->setCancelButtonText("Long Long Long Click this button to cancel");
dialog->setWindowModality(Qt::ApplicationModal);
dialog->adjustSize();
dialog->setValue(5);

标题和取消按钮文本被剪切。我调用了adjustSize(),但是没有用。如何调整对话框的大小以适应其内容?

在此处输入图像描述

4

1 回答 1

2

您可以使用以下内容:使用 QLayout...

QProgressDialog* dialog = new QProgressDialog("Message", "Close", 0, 10);
dialog->setWindowTitle("Long Long Long Long Title");
dialog->setCancelButtonText("Long Long Long Click this button to cancel");
dialog->setWindowModality(Qt::ApplicationModal);
dialog->setValue(5);

QVBoxLayout *layout = new QVBoxLayout;
foreach (QObject *obj, dialog->children()) {
    QWidget *widget = qobject_cast<QWidget *>(obj);
    if (widget)
        layout->addWidget(widget);
}
dialog->setLayout(layout);
于 2015-12-10T12:40:16.323 回答