2

What I'm trying to do

I am trying to create a subclass of QWizardPage that looks somewhat like this,but has a slight tweak. I want to disable the next button when a counter variable is more than 0. (It can't be 0 from the get-go due to some functionality that requires it to go x..x-1...0).

What I've tried

Reimplement isComplete() and emit completeChanged() in the constructor

bool DemoWizardPage::isComplete()
{
  return ! (counter > 0); //Also tried just return false;
}

Reimplement initializePage and disable the next button from there

void DemoWizardPage::initializePage()
{
  qDebug() << "QWizardPage:: initialize page";

  if (!this->isComplete())
  {
    qDebug() << "try to turn off next button";
    wizard()->button(QWizard::NextButton)->setDisabled(true);

    qDebug() << "next button enabled? "
             << wizard()->button(QWizard::NextButton)->isEnabled();
  }
}

Results so far

From stepping through the code I can see that the next button is disabled when the page loads. But then it is enabled again due to these 2 lines in QWizardPrivate (taken from qwizard.cpp)

 bool complete = page && page->isComplete();
 btn.next->setEnabled(canContinue && complete);

I am quite baffled as to why isComplete() is returning true here. I mean, I set my counter to be 2 at the beginning and I never decrease it. (And yes, I do emit a completeChanged() whenever I set the counter).

Any ideas?

4

1 に答える 1

2

QWizard は、QWizardPage::isComplete() に基づいて [次へ] ボタンの状態を自動的に管理します。その機能を initializePage() で自分で実装しないでください。isComplete() が呼び出されない理由は、QWizardPage から QWizardPage::isComplete constを実際に上書きしないためです。関数constを宣言すると、元の関数が適切に上書きされます。

于 2013-07-17T09:05:32.240 に答える