DaClown
DaClown

Reputation: 4569

QWizard: delete history of visited pages

I'm working on a project that basically follows a pre-defined structure, like a state machine or a wizard. I stumbled upon QWizard, its nextId() function seemed to be a good way to make my wizard dyamically load further pages. Now, it would be very nice to go back to earlier, already visited pages of the wizard. But even with overloaded nextId() I can't go back to that already visited pages.

Is is possible to clear the visited pages history? Or is there a better way to do this?

I use Qt by PyQt4 in Python, but that should make that much of a difference. Another way to do what I ask would be to add a similar page to the wizard and share the previous data with this page, but coming from mostly C++ I don't like the way to create dummy objects that mimic originals.

Edit: What I'm trying to do is to replicate a state machine with QWizard (because it almost is a state machine). For example, on page 1 data is loaded, then on page 2 additional computations happen that potentially extend page 1 data. By using the back button I can go back to page 1, but I can not "go back" with the next button because page 1 is already visited at this point. I tried it by overloading the nextId() functions but it doesn't work. This means I can not build a cyclic order of pages, which I would like to do.

Upvotes: 2

Views: 768

Answers (2)

abhiarora
abhiarora

Reputation: 10430

I had similar requirements in the past. I was developing an application in C++ which requires QWizard for licensing and calibration of my Hardware Device and found out there is no provision in the QWizard to switch to previously visited Page/ID.

I came up with a workaround in C++. However, you can easily port to python. Documentation over here shows pyqt has methods setStartId and restart. You can use them to implement the logic in python.

LicenseWizard::LicenseWizard(QWidget *parent)
    : QWizard(parent)
{
    setPage(Page_Intro, new IntroPage);
    setPage(Page_Evaluate, new EvaluatePage);
    setPage(Page_Register, new RegisterPage);
    setPage(Page_Details, new DetailsPage);
    setPage(Page_Conclusion, new ConclusionPage);

    setStartId(Page_Intro);

#ifndef Q_WS_MAC
    setWizardStyle(ModernStyle);
#endif
    setOption(HaveHelpButton, true);
    setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo.png"));

    connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));
    QAbstractButton *b = this->button(QWizard::BackButton);
    connect(b, SIGNAL(clicked()), this, SLOT(goToSecondPage()));

    setWindowTitle(tr("License Wizard"));
}

void LicenseWizard::goToSecondPage()
{
    setStartId(Page_Evaluate);
    restart();
}

Upvotes: 1

Eli Bendersky
Eli Bendersky

Reputation: 273476

I'm not sure I see the logical connection between the different questions you're asking here. If you want to go back to already visited pages, why do you want to delete the history?

With the help of overloading the nextID method of either the QWizard or separate QWizardPages you can easily implement any custom visiting order you desire. Use the hasVisitedPage method to find out whether some page was already visited. visitedPages returns the list of IDs of visited pages, in the order in which the pages were visited.

What else do you need?

Upvotes: 0

Related Questions