Where to control the QWizard button?
Asked Answered
S

2

10

I'm using Qt, and I use a QWizard object which contains several pages. when it comes to a specific page, I want to hide the "Next" button first, and shows it after the user do something (such as clicking on a radiobutton...)

I want to do some customize control of the wizard when this specific page shows up. the question is, I know how to hide the button, but I don't know which function I should use. I tried the QWizardPage constructor, the initializePage function, the "show" function, but all of these function didn't work.

If I put the button control in the wizard page constructor, the program will crash since the wizard object is not there yet.

If I put it in initializePage function, some QWizard function will reset the buttons after the initializePage function, and all the customized setting will gone.

And the show function seems cannot be overwritten.

I really cannot figure out which function is usable. Is there any function like OnSetActive in MFC or Load in JAVA?? Which will be called when a page is going to shows out?

Schaper answered 3/8, 2010 at 23:23 Comment(0)
C
9

The best solution is probably the one provided by using QWizardPage::registerField. It allows you to define mandatory fields/radio buttons/etc. and the Next and/or Finish buttons in your wizard are enabled only when all mandatory fields are filled/checked.

See http://doc.trolltech.com/4.6/dialogs-licensewizard.html for an example which makes use of this functionality.

EDIT: QWizard::button provides access to the buttons in the wizard. Have you tried something like myWizard->button(QWizard::NextButton)->setEnabled(false) ?

Conga answered 4/8, 2010 at 6:16 Comment(3)
Thanks, but my question is a little different. Using registerField,The Next and Finish buttons are decided together. What I want to do is to decide whether a page is final page or not, in other words, I want to decide if the wizard should end up eariler. I know I can use the setFinalPage, however, after setting a page to final page, the Finish button shows up, that's good, but the next button is still there, that's what I want to avoid. I want to disable it or hide it. isComplete or registerField control the Next and Finish buttons together, and I want them to be separated.Schaper
@Claire Huang: Added a new idea to my answer; I hope it helps.Conga
Hi Greg: Sorry that I didn't see your comment and thanks for your help. Yes I do try to set the button in initializePage function, however, it seems that the button are been reset after the initializePage(). I cannot find the correct function to set the buttons.Schaper
R
5

To disable the next button you can subclass QWizardPage and reimplement isComplete(). When it returns true then QWizard will enable the button. The subclass has to emit the 'completeChanged()' signal when you change the state of isComplete(). The documentation for QWizardPage explains how to do it.

Possibly you could also use

parent->button(QWizard::NextButton)->setVisible(false)

to hide the button.

Rheum answered 23/11, 2010 at 3:1 Comment(1)
Thanks for your reply. How can I emit catch signal finish button pressed from my wizard.Adenosine

© 2022 - 2024 — McMap. All rights reserved.