2015-12-10 538 views
0

我用下面的代碼進行測試:QProgressDialog:如何調整對話框的大小以適合其內容?

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(),但它不起作用。如何調整對話框的大小以適應其內容?

enter image description here

+0

使用'Layout's,選中[文件](http://doc.qt.io/qt- 5 /實例-layouts.html)。 – KernelPanic

+0

當按鈕有這麼長的名字時,它看起來並不漂亮。您最好設置一個簡短的名稱並使用長描述作爲工具提示文本。 – vahancho

+0

@KernelPanic,QProgressDialog由QT提供,我可以編輯它的佈局嗎? – ldlchina

回答

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); 
+0

解決方案有效。謝謝。 – ldlchina

相關問題