2013-05-07 132 views
0

我正在尝试做一些看起来很简单的事情,但我无法让它工作。我想在我的QWizard中制作更大的按钮。以下是代码:更改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; 
} 

此代码不执行任何操作。是否有可能改变按钮的几何形状?或者它被禁止?

谢谢

回答

1

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

你也可以编程设置qss(不是最好的实践)。

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

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

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

button(QWizard::CancelButton)->setStyleSheet("height: 50px"); 
+0

宾果!这两个解决方案都很完美非常感谢 – peterphonic 2013-05-07 19:14:18

+0

其实,刚发现当我的QWizard在AeroStyle中时,setStyleSheet不起作用。 setStyleSheet适用于所有带有modernStyle的按钮。任何想法? – peterphonic 2013-05-07 19:32:10