我正在使用QT来实现一些UI程序。在此程序中,我需要一个进度对话框。我尝试使用build-In-in qprogressdialog,它可以正常工作,但是在我的情况下,我需要在单击“取消按钮”时确认(使用另一个对话框)。

在qprogressdialog中,一旦单击“取消”按钮,“进度对话框”将被取消,因此,我尝试实现自己的进度对话框(非常简单,使用Progress Bar的对话框)。但是,如果我使用自己的进度对话框,则存在一些问题。它不能移动或点击。一旦我尝试将其移动并丢失对话框的焦点,进度栏将不会再更新,并且无法再次获得焦点。我尝试设置不同的模式,但是qt :: application -modal或qt :: window -modal的情况相同。

如果有人知道如何修改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();
};

来源:

#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;
}
有帮助吗?

解决方案

从QT文档中:当单击“取消”按钮并默认将其连接到CANCEL()插槽时,发出了信号qprogressdialog :: custiced()。

您是否尝试将取消信号连接到您自己的验证插槽,如果用户确认是选择,则取消对话框?

之前,连接自己的插槽,使用qobject :: disconnect()从取消插槽中断开已取消信号的连接: http://doc.qt.io/archives/qt-4.7/qobject.html#disconnect

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top