如何为QWizard配置样式表

时间:2013-10-16 18:05:54

标签: qt

我无法找到如何使用样式表或Qt Designer为QWizard配置BannerPixmap的答案。有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

您可以在向导或向导页面上设置Pixmap属性;例如:

    self.setPixmap(QtGui.QWizard.WatermarkPixmap, QtGui.QPixmap(":/plugins/eaf/eaf3.jpg"))

(pixmap是一些Qt资源)

此方法的第一个参数是向导角色。正如上面的评论所指出的,使用中的角色取决于向导样式:

  • WatermarkPixmap(由ClassicStyle和ModernStyle使用)
  • BannerPixmap(由ModernStyle使用)
  • LogoPixmap(由ClassicStyle和ModernStyle使用)
  • BackgroundPixmap(由MacStyle使用)

您可以使用以下命令显式设置向导样式:

setWizardStyle ( WizardStyle style )

[1] https://qt-project.org/doc/qt-4.8/qwizard.html#wizard-look-and-feel

答案 1 :(得分:0)

您可以在向导中自定义按钮,查看QWizard源代码以获取对象名称。

每个按钮都有其自己的对象名称。 https://code.woboq.org/qt5/qtbase/src/widgets/dialogs/qwizard.cpp.html#_ZL22object_name_for_buttonN7QWizard12WizardButtonE

static QString object_name_for_button(QWizard::WizardButton which)
{
    switch (which) {
    case QWizard::CommitButton:
        return QLatin1String("qt_wizard_") + QLatin1String("commit");
    case QWizard::FinishButton:
        return QLatin1String("qt_wizard_") + QLatin1String("finish");
    case QWizard::CancelButton:
        return QLatin1String("qt_wizard_") + QLatin1String("cancel");
    case QWizard::BackButton:
    case QWizard::NextButton:
    case QWizard::HelpButton:
    case QWizard::CustomButton1:
    case QWizard::CustomButton2:
    case QWizard::CustomButton3:
        // Make navigation buttons detectable as passive interactor in designer
        return QLatin1String("__qt__passive_wizardbutton") + QString::number(which);
    case QWizard::Stretch:
    case QWizard::NoButton:
    //case QWizard::NStandardButtons:
    //case QWizard::NButtons:
        ;
    }
    Q_UNREACHABLE();
    return QString();
}

在样式表中:

/*Next button in the wizard */
QPushButton#__qt__passive_wizardbutton1
{
    background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 rgba(35, 200, 183, 100%), stop:1 rgba(35, 167, 212, 100%));
    color: white;
    font: bold;
}

QPushButton#qt_wizard_finish
{
    background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 rgba(35, 200, 183, 100%), stop:1 rgba(35, 167, 212, 100%));
    color: white;
    font: bold;
}

QPushButton#qt_wizard_commit
{
    background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 rgba(35, 200, 183, 100%), stop:1 rgba(35, 167, 212, 100%));
    color: white;
    font: bold;
}