Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 将标题和图标图像添加到QProgressDialog_Qt_Progressdialog - Fatal编程技术网

Qt 将标题和图标图像添加到QProgressDialog

Qt 将标题和图标图像添加到QProgressDialog,qt,progressdialog,Qt,Progressdialog,我正在尝试更改默认QProgressDialog以显示更新状态: ASSERT( connect( &(updater.GetUpdateInstaller()), SIGNAL(progressValue(int)), progressDialog, SLOT(setValue(int)) ) ); ASSERT( connect( &(updater.GetUpdateInstaller()

我正在尝试更改默认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();

如何更改默认大小、添加图标图像和更改标题?

您可以通过设置对话框的大小和标签来更改对话框标题。标签可以保存
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
子类化,并在其他必要的小部件(如
qlabel
s和
QButtonGroup
s)旁边添加一个
QProgressBar

您可以通过设置对话框的大小和标签来更改对话框标题。标签可以保存
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
子类化,并在其他必要的小部件(如
qlabel
s和
QButtonGroup
s)旁边添加一个
QProgressBar

我认为您可以通过创建自己的QProgressDialog子类并添加自己的插槽来实现。 大概是这样的:

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

但这意味着你不能再单独升级方面了。它的用处取决于您正在做什么。

我认为您可以通过创建自己的QProgressDialog子类并添加自己的插槽来实现。 大概是这样的:

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

但这意味着你不能再单独升级方面了。它的用处取决于您正在做什么。

这也是一个很好的答案,但我更喜欢另一种方法,因为它具有更大的灵活性。谢谢你的回答。这也是一个很好的回答,但我更喜欢另一种方法,因为它有更多的灵活性。谢谢你的回答。