2
votes

I'm writing some wizard using Qt 5.2.1 under Ubuntu 13.10. I have header image and want to show it at the top of almost all wizard pages. So i opened QtDesigned, created new QWizardPage form and result looks like (conceptually):

QWizardPage in QtDesigner

Blue area at the top is my header image. It should takes all top area, from (0,0) to (window.width, image.height).

Then i just add this page to QWizard:

SetupWizard::SetupWizard(QWidget * parent) : QWizard(parent) {
    welcomePage_ = new SetupWizardWelcomePage(this);
    setPage(WELCOME_PAGE, welcomePage_);
    ...

And result is:

QWizardPage in running app

As you can see there are small margins at left, right and top of my header image. I've tried to change styling of QWizard, set fixed size and play with geometry - nothing helps me. Seems like this spacing is defined inside QWizard class, but i'm not sure about it.

So am i able to show header without spacing using QWizard? Or i have to create my own Wizard class?

1
How did you change styling of QWizard ? Take a look here doc.qt.digia.com/qq/qq20-qss.html , in "The Box Model" chapter ;)Martin
By styling QWizard i meant Wizard Style option, which set by setWizardStyle(WizardStyle style) and can be ClassicStyle, ModernStyle, MacStyle, AeroStyle and NStyles. Setting margin and padding to 0 in style sheets of QWizard won't help.serg.v.gusev
To my mind, you have to check margin and padding from both of your widgets (parents and son), not just QWizard.Martin
Thanks for idea, but this didn't help. I've wrote: "margin: 0; padding: 0; border: 0;"serg.v.gusev
@serg.v.gusev did you solve this in the end?Zmey

1 Answers

1
votes

Header's banner and logo can be set using

setPixmap(QWizard::BannerPixmap, bannerPixmap);
setPixmap(QWizard::LogoPixmap, logoPixmap);

However, wizard window will no longer be resizable horizontally. Also, I wanted to customize header even more, so I added a custom header to QWizardPage instead. This produced white border around the page which you also observed.

Border can be removed with this hack in QWizard's constructor:

QWidget *flickerWidget = (QWidget *)(children()[0]);
flickerWidget->layout()->setContentsMargins(0, 0, 0, 0);

But it's not practical as separator above buttons will also lose padding plus there will be no padding around buttons.

What I done in the end is:

  • Created a new widget inherited from QDialog with QVBoxLayout layout in which I put my custom header widget + QWizard instance.

  • Connected to wizard's currentIdChanged(int) signal and updated custom header's title and subtitle in signal's handler.

  • If ESC was pressed, wizard widget destroyed itself so I routed it's finished() signal to my dialog's done() to close it as well:

connect(m_wizard, SIGNAL(finished(int)), this, SLOT(done(int)));

Optional: I also made a custom subclass of QWizardPage in which I overridden setTitle and setSubTitle and didn't call parent's ones so original header would not be visible. In currentIdChanged() handler, I queried page subclass for title/subtitle and set it in custom header.

I also used setWizardStyle(QWizard::ClassicStyle) so wizard would have appropriate background color / padding without it's native title/subtitle. ModernStyle used to produce weird colors when title wasn't set.

It works in the end, but maybe creating the wizard from scratch would be easier.