How to remove the horizontal line in a QWizard with a stylesheet?

旧巷老猫 提交于 2020-01-14 18:55:12

问题


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

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();
}

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.

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

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

I hope someone could help me.


回答1:


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.



来源:https://stackoverflow.com/questions/52667937/how-to-remove-the-horizontal-line-in-a-qwizard-with-a-stylesheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!