如何在带有样式表的QWizard中删除水平线? [英] How to remove the horizontal line in a QWizard with a stylesheet?

查看:228
本文介绍了如何在带有样式表的QWizard中删除水平线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理QWizard的样式表,我想删除按钮上方的水平线.

I am working on stylesheet of a QWizard and I would like to remove the horizontal line just above the push button.

我已经在此处发布了一个最小示例,该问题已由scopchanov从最小示例中解决,但是我在我的项目中有一些代码行避免了解决方案的工作,所以我在这里发布了另一个问题.

I've already posted a minimal example here, the question was solved by scopchanov from the minimal example, but I have some lines of code in my project that avoids the solution to work, so I post another question here.

这是我的代码(完整的可构建示例可以从要旨中下载在这里 ):

Here is my code (the complete buildable example can be downloaded from the gist here):

licensewizard.h

#include <QWizard>

class LicenseWizard : public QWizard {
  Q_OBJECT
public:
  LicenseWizard(QWidget *parent = 0);
};

licensewizard.cpp

#include <QApplication>
#include <QtWidgets>
#include "licensewizard.h"

LicenseWizard::LicenseWizard(QWidget *parent) : QWizard(parent) {
    setWizardStyle(ModernStyle);

    // solution from @scopchanov https://stackoverflow.com/a/52541248/8570451
    QPalette p(palette());
    p.setColor(QPalette::Mid, p.color(QPalette::Base));
    setPalette(p);
}

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    // this line breaks @scopchanov solution.
    // replace QLabel by QPushButton, or anything else... still broken.
    qApp->setStyleSheet("QLabel { color:black; }");

    LicenseWizard wizard;
    wizard.show();

    return app.exec();
}

正如scopchanov所说,我使用了QPalette技巧.但是我在qApp上定义了一个很大的样式表,这就是造成我问题的原因.使用很小的样式会遇到相同的问题.

As scopchanov said, I used the QPalette trick. But I have a big style sheet defined on the qApp and this is the cause of my problem. Using a very small style give the same problem.

要重现的步骤是在QApplication声明之后添加以下行:

The step to reproduce is to add this line after the declaration of the QApplication:

qApp->setStyleSheet("QLabel { color:black; }");

我希望有人能帮助我.

推荐答案

要解决此问题,请设置整个应用程序的调色板,而不仅仅是LicenseWizard类,如下所示:

To fix this, set the palette of the whole application, instead of just the LicenseWizard class, like this:

LicenseWizard::LicenseWizard(QWidget *parent) : QWizard(parent) {
    setWizardStyle(ModernStyle);
}

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QPalette p(qApp->palette());

    p.setColor(QPalette::Mid, p.color(QPalette::Base));
    qApp->setPalette(p);
    qApp->setStyleSheet("QLabel { color:black; }");

    LicenseWizard wizard;
    wizard.show();

    return app.exec();
}

注意:如我对链接问题的回答中所述,如果此颜色角色由其他任何项目使用,则其颜色也会受到影响.

Note: As mentioned in my answer to the linked question, if this color role is used by any other item, its color would be affected as well.

这篇关于如何在带有样式表的QWizard中删除水平线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆