开发者

QWizard: Change height/dimensions of title field

开发者 https://www.devze.com 2023-03-31 01:34 出处:网络
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.

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 screen开发者_如何学JAVAshot, 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消