0

我正在尝试做一些看起来很容易的事情,但我无法让它发挥作用。我想让 QWizard 中的按钮变大。这是代码:

#include "wizard.h"
#include "ui_wizard.h"
#include "QAbstractButton"
Wizard::Wizard(QWidget *parent) :
    QWizard(parent),
    ui(new Ui::Wizard)
{
    ui->setupUi(this);
    QRect rect = this->button(QWizard::NextButton)->geometry();
    this->button(QWizard::NextButton)->setGeometry(rect.x(), rect.y(), rect.width(), 40);

    rect = this->button(QWizard::CancelButton)->geometry();
    this->button(QWizard::CancelButton)->setGeometry(rect.x(), rect.y(), rect.width(), 40);

    rect = this->button(QWizard::BackButton)->geometry();
    this->button(QWizard::BackButton)->setGeometry(rect.x(), rect.y(), rect.width(), 40);

}

Wizard::~Wizard()
{
    delete ui;
}

这段代码什么都不做。是否可以更改按钮的几何形状?还是被禁止?

谢谢

4

1 回答 1

2

更好的是使用 QSS(Qt 样式表)自定义用户界面。您可以使用QApplication::setStyleSheet()读取您的 qss 文件并为整个应用程序设置样式表。

您也可以以编程方式设置 qss(不是最佳实践)。

setStyleSheet("QAbstractButton { height: 50px }");

什么设置了小部件上所有按钮的高度。

在最坏的情况下,你可以试试这个:

button(QWizard::CancelButton)->setStyleSheet("height: 50px");
于 2013-05-07T19:06:51.257 回答