[Qt-interest] QWizardPage::wizard() overprotected?
Niels Dekker - no return address
noreply at this.is.invalid
Thu Dec 11 20:03:32 CET 2008
>> Do you mean that it's simply impossible to place a wizard inside a
>> QMainWindow, and have it work properly?
Andreas Pakulat wrote:
> That depends on the implementation of QMainWindow, QWizard and
> QDialog. In general QDialog is supposed to be a top-level window, so
> there might be code that assumes this and you might get problems
> when embedding it into a mainwindow.
I must admit I've encountered one such problem already: when a user
would press Escape, the embedded wizard would close, but the main window
would still be there. I hope to fix that by overriding
QWizard::keyPressEvent(QKeyEvent*) in my derived wizard class, to deal
with key == Qt::Key_Escape.
> Besides a wizard with widgets, then the next/prev/finish buttons
> and then a statusbar is pretty uncommon and might confuse
> users.
I hope not! My status messages certainly aren't meant to confuse the
users!
>> It looks like Qt doesn't supports adding a statusbar to a dialog.
>> At least not within the Qt4 Designer, or the VS Integration.
> Well, some things you have to do manually. I don't really understand
> why you have a .ui file for the dialog itself. After all you can't
> really create wizard+wizardpages in Qt designer anyway.
I guess you're right, I probably shouldn't have created a .ui file for
the QWizard. Thanks for the eye opener! While I find the designer (VS
Integration) very convenient when designing my wizard pages, it only
offers very limited ways to design the wizard itself.
> So you're not adding the statusbar to the dialog, but to the widget
> of the page in your QWizardPage subclass. And then each individual
> page is a subclass of that and just calls setWidget() with a widget
> generated from a form.
I'm not sure. I'd rather have the statusbar at the bottom of the main
window, not at the bottom of the embedded page. But I can still
consider adding the statusbar manually, doing "new
QStatusBar(myWizard)", as in your code example.
----------------------------------------------------------------------
>> I mean, what does Qt protect me against?
Scott Aron Bloom wrote:
> That's a different question...
It's _the_ question of my original post: why isn't wizard() public?
>> 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?
> Only if you want to violate basic OODA principals...
> Which sometimes you have to do, but in this case
> there are much easier approaches...
>
> First, create a signal in each page
> Second, create a signal on your custom wizard
> Third, create a slot in you main window
>
> Then when the constructor of the wizard is creating each page, it
> connects each pages signal to its own.
>
> When the main window constructs the wizard, it connects the signal to
> its slot.
>
> Then any page or the wizard itself can easily set the message of the
> status bar...
Thanks, such an approach is certainly worth considering to me. Having
the pages send their status messages by means of signals, following the
Observer pattern. I appreciate the fact that the pages do not need to
know how the status messages get displayed, or what widget will display
them, when following this approach.
> Or another solution... Create a BASE CLASS..
>
> Ie,
> class MyWizardPage : public QWizardPage
> {
> QStatusBar * getStatusBar()
> {
> const QMainWindow* const mainWindow =
> dynamic_cast<const QMainWindow *>(wizard->parent());
> assert(mainWindow != NULL);
>
> QStatusBar* statusBar = mainWindow->statusBar();
> assert(statusBar != NULL);
> return statusBar;
> }
> }
>
> Both of these methods are MUCH MUCH cleaner, in general, if you find
> your self creating a global function to take in a class pointer to do
> something to the pointer, make it a method on a derived class...
I don't think there's such a fundamental difference between doing
getStatusBar(*this), and this->getStatusBar(), but I agree that it's
worth consider adding my own WizardPage base class, inherited from
QWizardPage, as you're suggesting.
Thanks so far to you all. I won't be programming anymore today, but
your replies are certainly helpful to me.
Kind regards, Niels
More information about the Qt-interest-old
mailing list