问题
I'm currently trying to implement a simple "First steps" Wizard for a Python/Qt application I'm working on. This is really easy to do with Designer, but as usual the devil lies in the details. My problem is that the 'Title' field is way too big for me (~50% of the available screen estate). Here is a screenshot, and there the *.ui-file.
I've already had a look at all the QWizard/QWizardPage properties and couldn't find anything that referred to the size/styling of the 'Title' field. Is there any way to do this (maybe using a custom stylesheet?) or am I out of luck?
回答1:
The title label is in an internal QGridLayout
, and unless you either add a layout to the page (or explicitly set the vertical size policy of the page to MinimumExpanding
or Expanding
) to force the grid cell containing the page to expand, the title will always take 50% of the total height.
回答2:
If the pixmap is set, like with the QWizard::WatermarkPixmap
on the QWizard::ModernStyle
, the height will be locked no matter what.
To get around this, use setSideWidget()
.
In the constructor for your subclass of QWizard
this->setWizardStyle(QWizard::ModernStyle);
// setPixmap(QWizard::WatermarkPixmap, QPixmap(":/watermark.gif"));
QWidget * sideWidget = new QWidget();
QGridLayout * gridLayout = new QGridLayout();
QLabel * label = new QLabel();
label->setPixmap(QPixmap(":/watermark.gif"));
sideWidget->setLayout(gridLayout);
gridLayout->addWidget(label);
this->setSideWidget(sideWidget);
//this->setSizePolicy(QSizePolicy::MinimumExpanding ,QSizePolicy::MinimumExpanding );
And lastly to make the title box adjust upon a fontsize change, the easiest hack is to adjust the height of a pixmap and set it in the QWizard::LogoPixmap.
int numOfLinesInTitleBox = 2;
QPixmap p(1,this->fontMetrics().height()*numOfLinesInTitleBox);
p.fill(Qt::transparent);
setPixmap(QWizard::LogoPixmap, p);
this->adjustSize();
Hope that helps.
来源:https://stackoverflow.com/questions/7219323/qwizard-change-height-dimensions-of-title-field