QT を使用して UI プログラムを実装しています。このプログラムでは、進行状況ダイアログが必要です。組み込みの QProgressDialog を使用しようとしましたが、正常に動作しますが、私の場合は、「キャンセル ボタン」をクリックしたときに (別のダイアログで) 確認する必要があります。
QProgressDialog では、キャンセル ボタンをクリックすると進行状況ダイアログがキャンセルされるため、独自の進行状況ダイアログ (非常に単純な、進行状況バー付きのダイアログ) を実装しようとしました。ただし、独自の進行状況ダイアログを使用すると、いくつかの問題があります。移動もクリックもできません。移動しようとしてダイアログがフォーカスを失うと、進行状況バーはそれ以上更新されず、再びフォーカスを得ることができません。別の Modality を設定しようとしましたが、Qt::ApplicationModal または Qt::WindowModal のいずれかで同じ状況が発生します。
QProgressDialog を変更して確認要件を満たす方法を誰かが知っている場合、または私のコードのどこに問題があるかを知っている場合は、私の進行状況ダイアログクラスを次に示します。
ヘッダ:
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
void setRange(int minimum, int maximum);
void setValue(int value);
void setLabelText(QString labtext);
bool wasCanceled();
private:
Ui::Dialog *ui;
bool cancelStatus;
private slots:
void cancel();
};
出典:</p>
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
cancelStatus = false;
ui->progressBar->setRange(0,1);
ui->progressBar->setValue(0);
//this->setWindowModality(Qt::WindowModal);
show();
}
Dialog::~Dialog(){
delete ui;
}
void Dialog::setRange(int minimum, int maximum){
ui->progressBar->setRange(minimum,maximum );
}
void Dialog::setValue(int value){
this->ui->progressBar->setValue(value);
}
void Dialog::setLabelText(QString labtext){
this->ui->label->setText(labtext);
}
void Dialog::cancel(){
// pop up the confirm dialog here
// cancelStatus = true if the confirm dialog is accepted, else do nothing .
}
bool Dialog::wasCanceled(){
return cancelStatus;
}