我测试下面的代码:
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(),但它没有用。如何调整对话框的大小以适应其内容?
答案 0 :(得分: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);