簡體   English   中英

QProgressDialog:如何調整對話框的大小以適合其內容?

[英]QProgressDialog: How to adjust the size of the dialog to fit its contents?

我用下面的代碼測試:

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(),但是它沒有用。 如何調整對話框的大小以適合其內容?

在此處輸入圖片說明

您可以使用以下內容:使用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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM