[Qt-interest] QWizardPage::wizard() overprotected?
Andreas Pakulat
apaku at gmx.de
Thu Dec 11 11:32:30 CET 2008
On 11.12.08 10:50:27, Niels Dekker - no return address wrote:
> Scott Aron Bloom wrote:
> > Since your deriving from WizardPage anyway.. why not just overload
> > wizard() and make it public?
>
> Thanks for your reply. So you say I'd have to override wizard() on all of my
> derived WizardPage classes, to make it public. But then why wasn't it public
> in the first place? I mean, what does Qt protect me against?
>
> > That said, why do you need access to the wizard outside of the
> > WizardPage?
>
> >>From within any of my pages, I need to find my way back to the status bar of
> my wizard. Unfortunately, a QWizard cannot have a status bar, so I had to put
> it onto a QMainWindow. Anyway, to avoid code duplication, I wrote a single
> function to get the status bar belonging to my wizard:
>
> // Returns the status bar, specific to my application.
> QStatusBar& getStatusBar(const QWizardPage& page)
> {
> // Get the "protected" wizard from the page.
> const QWizard* const wizard = getWizard(page);
> assert(wizard != NULL);
>
> // My wizard has a QMainWindow as parent.
> const QMainWindow* const mainWindow =
> dynamic_cast<const QMainWindow *>(wizard->parent());
> assert(mainWindow != NULL);
>
> QStatusBar* statusBar = mainWindow->statusBar();
> assert(statusBar != NULL);
> return *statusBar;
> }
>
>
> Now I can directly get the status bar, from within any of my pages:
> getStatusBar(*this).showMessage(tr("Status okay!"));
>
> Doesn't that sound reasonable to you?
Not to me :) First of all, QWizard is a QDialog, embedding it into any
other widget is not a supposed usage of that class.
Why can't the statusbar be part of the page itself? A dialog usually has
the bottom parts for its buttons and the rest is the page of your dialog.
To avoid code-duplication in this case, create a QWizardPage subclass that
simply has a QStatusBar* statusBar() member and a setWidget() function to
set the main widget of the page. Then it just needs to put this widget
into a vertical layout with the statusbar. Thats it, much cleaner with no
hacks involved.
Andreas
--
Don't you wish you had more energy... or less ambition?
More information about the Qt-interest-old
mailing list