Reputation: 84
I am working with a QWizard
that really should've been implemented as a QStackedWidget
but it's too far gone to change now. I have a QPushButton
I would like to call a SLOT from, and that SLOT then calls nextId()
after doing other things.
I have tried removing the next button with:
QList<QWizard::WizardButton> wizardButtons;
wizardButtons << QWizard::Stretch << QWizard::BackButton << QWizard::FinishButton << QWizard::CancelButton;
wizard()->setButtonLayout(wizardButtons);
This worked to remove the button, but now nextId()
doesn't transition to another page of the wizard.
I also tried
wizard()->button(QWizardButton::NextButton)->hide();
But that didn't have any effect
How can I hide the next button so I am still able to transition pages when my
QPushButton
in the top right is clicked? Or is there a way to force the wizard to my desired page without the next button?
This GUI was done programatically, I cannot just use creator.
Upvotes: 0
Views: 814
Reputation: 11
This works for me,
QAbstractButton *nextButton = wizard()->button(QWizard::NextButton);
nextButton->setStyleSheet("background-color:transparent; width: 0px; height: 0px;");
Upvotes: 1
Reputation: 1330
I think calling next()
is the right way to proceed to the next page.
There may not be an elegant way to hide the next button but you can disable it: Override QWizardPage::isComplete()
to return false whenever you want the next/finish button to be disabled. Emit completeChanged()
whenever isComplete()
needs to be be reevaluated.
MyWizardPage::MyWizardPage(QWidget * parent)
: QWizardPage(parent)
, ui(new Ui::MyWizardPage)
{
ui->setupUi(this);
// Emit completeChanged() whenever the email field changes.
connect(ui->email, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
}
bool MyWizardPage::isComplete() const
{
// Enable the next/finish button when email has more than 5 chars
return ui->email->text().length() > 5
}
To keep the next button disabled all the time just always return false from isComplete()
and don't worry about ever emitting completeChanged()
.
Upvotes: 0
Reputation: 84
As a workaround, I was able to call
wizard()->next();
from the SLOT which forced a call to nextId()
.
This is probably not the best way to handle this but it is working. I will accept another answer if one is presented, or alterations/comments on the validity of my solution.
Upvotes: 0