我正在尝试更改默认的QProgressDialog以显示更新状态:
ASSERT( connect( &(updater.GetUpdateInstaller()), SIGNAL(progressValue(int)),
progressDialog, SLOT(setValue(int)) ) );
ASSERT( connect( &(updater.GetUpdateInstaller()), SIGNAL(progressText(QString)),
progressDialog, SLOT(setLabelText(QString)) ) );
//update the packages using the updater
updater.UpdatePackages();
如何更改默认尺寸,添加图标图像并更改标题?
答案 0 :(得分:2)
您可以按setWindowTitle()
更改对话框标题,设置其大小及其标签。标签可以包含QString
或QPixmap
,但不能包含两者。
QProgressDialog * dialog = new QProgressDialog(this) ;
// fix dialog height
dialog->setMinimumHeight(400);
dialog->setMaximumHeight(400);
// set dialog title
dialog->setWindowTitle("Progress Dialog");
QLabel * labl = new QLabel(this);
labl->setPixmap(QPixmap(":/images/icon.png"));
labl->setText("text");
dialog->setLabel(labl);
如果您需要更广泛的灵活性,则应该为QDialog
创建子类,并在QProgressBar
和QLablel
s等所有其他必需小部件旁边添加QButtonGroup
。
答案 1 :(得分:2)
我认为您可以通过创建自己的QProgressDialog子类并添加自己的SLOT来使其工作。 像这样:
MyQProgressDialog.h
class MyQProgressDialog : public QProgressDialog
{
Q_OBJECT
public slots:
setTitle(QString title);
setIcon(QIcon icon);
setSize(int w, int h);
};
MyQProgressDialog.cpp
void MyQProgressDialog::setTitle(QString title)
{
setWindowTitle(title);
}
void MyQProgressDialog::setIcon(QIcon icon)
{
setWindowIcon(icon)
}
void MyQProgressDialog::(int w, int h)
{
setFixedSize(w, h);
}
然后改变你的联系:
ASSERT( connect( &(updater.GetUpdateInstaller()), SIGNAL(progressValue(int)), progressDialog, SLOT(setValue(int))));
ASSERT( connect( &(updater.GetUpdateInstaller()), SIGNAL(progressText(QString)), progressDialog, SLOT(setLabelText(QString))));
ASSERT( connect( &(updater.GetUpdateInstaller()), SIGNAL(progressIcon(QIcon)), progressDialog, SLOT(setIcon(QIcon))));
ASSERT( connect( &(updater.GetUpdateInstaller()), SIGNAL(progressSize(int, int)), progressDialog, SLOT(setSize(int, int)));
//update the packages using the updater
updater.UpdatePackages();
这包括在更新程序中创建2个新信号progressIcon(QIcon)和progressSize(int,int)。
编辑:现在我想起来,如果你顺便说一下,创建一个可以更新所有东西的新插槽可能会更容易,例如:
//MyQProgressDialog.h
class MyQProgressDialog : public QProgressDialog
{
Q_OBJECT
public slots:
updateEverything(Int value, QString text, QString title, QIcon icon, Int w, Int h);
};
//MyQProgressDialog.cpp
void MyQProgressDialog::updateEverything(Int value, QString text, QString title, QIcon icon, Int w, Int h)
{
setWindowTitle(title);
setWindowIcon(icon);
setFixedSize(w, h);
setValue(value);
setLabelText(text);
}
//Connection
ASSERT( connect( &(updater.GetUpdateInstaller()), SIGNAL(progress(int, QString, QString, QIcon, Int, Int)), progressDialog, SLOT(updateEverything(progress(int, QString, QString, QIcon, Int, Int)));
但这意味着你不能再单独更新方面了。取决于你正在做什么,这可能很有用。