Megasa3
Megasa3

Reputation: 764

Qt: How to change QWizard default buttons

I'm making a program with Qt 4.8.5 on a Fedora system (unix). It's a QWizard structure with its QWizardPages.

I needed to change the default QWizard buttons (back, next, finish...) and customize it. I found I could do it putting the next lines on the constructor of my QWizard class called BaseWizard (class BaseWizard : public QWizard)

QList<QWizard::WizardButton> button_layout;
button_layout <<QWizard::Stretch << QWizard::CustomButton1 << QWizard::BackButton << QWizard::NextButton << QWizard::FinishButton;

this->setOptions(QWizard::NoDefaultButton);

With that what I have from left to right is one custom buttons, the back button, the next button and the finish button, and when I want I can show or hide the custom buttons with SetVisible() / SetDisabled() / setEnabled() functions.

That worked perfect for what I wanted until now... I have to make some changes to the program so I need to change those buttons depending on the page the user is. As I said before, I know I can change the visibility of CustomButton 1 for example BUT I can't do the same with back button so... my quesiton is: How can I decide which buttons I show in every QWizardPage (and their text) and which is the best way to do it?

I've tried creating a function on my BaseWizard

// Function to have only 2 custom buttons
void BaseWizard::ChangeButtons()
{
    QList<QWizard::WizardButton> button_layout;
    button_layout <<QWizard::Stretch << QWizard::CustomButton1 << QWizard::CustomButton2;
    setButtonLayout(button_layout);
 }

And then in the QWizardPage (lets call it WP) using it like:

BaseWizard *bz;
bz->ChangeButtons();

But when I do that nothing changes.I can still see the NextButon for example. I have tried also using first a button_layout.clear(); to see if clenaing it before adding the buttons works, but not.

I have also tried changing the text of CustomButton1. If I do it in the WP after calling ChangeButtons with wizard()->button(QWizard::CustomButton1)->setText("TEXT CHANGED"); Then the text changes but if I put it in the ChangeButton() function with this->button(QWizard::CustomButton1)->setText("BBBBB"); it does nothing (But its entering into the funcion). Ofc if I try to change the text of CustomButton2 in WP nothing happens because I can't still see that button... so any idea of what I am doing wrong or how could I get what I try will be very apreciated,

Thank you so much.

Upvotes: 0

Views: 1818

Answers (1)

Megasa3
Megasa3

Reputation: 764

Ok, I finally knew why was my program crashing... I put here the solution if anyone needs it in the future:

BaseWizard *bz; // <-- HERE is the problem
bz->ChangeButtons();

I was not initializing the pointer so it has to be changed to:

BaseWizard *bz = dynamic_cast<BaseWizard*>(wizard());

Upvotes: 0

Related Questions