我创建了一个QProgressDialog,并为它设置了一个QProgressBar。设置格式
“正在处理节%v,共%m。已完成百分比:%p。”
到QProgressBar去。但文本会被剪切,而不是整个进度条显示在对话框上。

如何调整宽度以显示整个进度条?
发布于 2015-11-23 19:45:56
下面是一个使用QFontMetrics获取进度条文本宽度的示例,然后在此基础上为进度条本身添加100px。当对话框显示时,它的大小将调整为此宽度。
auto dialog = new QProgressDialog();
dialog->setWindowTitle("Progress");
dialog->setLabelText("Test progress dialog");
auto bar = new QProgressBar(dialog);
bar->setTextVisible(true);
bar->setValue(50);
bar->setFormat("Processing section %v of %m. Percentage completed: %p");
dialog->setBar(bar);
// Use QFontMetrics to get the width of the bar text,
// and then add 100px for the progress bar itself. Set
// this to the initial dialog width.
int width = QFontMetrics(bar->font()).width(bar->text()) + 100;
dialog->resize(width, dialog->height());
dialog->show();这使您可以避免对宽度进行硬编码,尽管这有点复杂。我认为像下面这样设置一个合理的最小宽度可能是一个更好/更简单的解决方案:
dialog->setMinimumWidth(300);https://stackoverflow.com/questions/33864440
复制相似问题