1

I have a QWizardPage where user is supposed to go through certain steps, at the end of which there is a button "Test". If user presses that button, two things happen:

  1. "Next" button gets enabled in order to go to the next page of the QWizard. This is achieved by emitting a button's special signal which is connected to QWizardPage:

    this->registerField("test*", m_button, "text", SIGNAL(testDone()));

m_button is derived from QPushButton with a custom signal testDone().

  1. Button name is changed to "Try again" in order to offer an option to try the series of steps all over again. If user presses the button, the GUI elements return to the initial state (except disabling the button "Next" on QWizard).

The question is: for the second scenario, how do I make sure the "Next" button gets disabled after being enabled by the emitted testDone() signal?

I thought if I disconnect the particular signal testDone() from QwizardPage (after it is emitted), it would give the desired results, however, it did not work. I tried to disconnect everything on the QWizardPage (e.g. this->disconnect), but that also didn't work. Any other ideas?

4

1 回答 1

2

要控制页面“准备就绪”,您通常会覆盖QWizardPage::isComplete并通过QWizardPage::completeChanged.

所以对于你的例子,你可以给你的按钮一个属性并相应地连接它:

class MyButton : public QPushButton
{
    Q_OBJECT

    Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged)

public:
    MyButton(QWidget *parent);
    bool isReady() const;

signals:
    void readyChanged();
};

每当按下按钮或测试完成时,发出信号,并从 isReady 函数返回所需的按钮状态。

在您的向导页面中,覆盖isComplete为:

bool isComplete() const {
    return QWizardPage::isComplete() && myButton->isReady();
}

并连接页面中的信号:

connect(myButton, &MyButton::readyChanged, this, &MyPage::completeChanged);
于 2017-10-18T09:10:30.860 回答