I am working on stylesheet of a QWizard
and I would like to remove the horizontal line just above the push buttons:
I have tried to recursively browse all the widgets and set their border to none, but no widget seems to have this border.
Here is my code (the complete buildable example can be found here):
licensewizard.h
#ifndef LICENSEWIZARD_H
#define LICENSEWIZARD_H
#include <QWizard>
class LicenseWizard : public QWizard
{
Q_OBJECT
public:
enum
{
Page_Welcome
};
LicenseWizard(QWidget *parent = 0);
};
class WelcomePage : public QWizardPage
{
Q_OBJECT
public:
WelcomePage(QWidget *parent = 0);
};
#endif
licensewizard.cpp
#include <QtWidgets>
#include "licensewizard.h"
#include <QtDebug>
LicenseWizard::LicenseWizard(QWidget *parent)
: QWizard(parent)
{
setPage(Page_Welcome, new WelcomePage);
setStartId(Page_Welcome);
setWizardStyle(ModernStyle);
setWindowTitle(tr("License Wizard"));
for (auto *widget : this->findChildren<QWidget *>())
{
widget->setStyleSheet("background:none; border:none; margin:0; padding:0;");
}
}
WelcomePage::WelcomePage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Welcome"));
}
Is it possible and how?
This ruler, QWizardRuler *bottomRuler
, is not affected by the stylesheet, because QWizardRuler
inherits QWizardHeader
and the line is drawn in the QWizardHeader::paintEvent
:
void QWizardHeader::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
painter.drawPixmap(0, 0, bannerPixmap);
int x = width() - 2;
int y = height() - 2;
const QPalette &pal = palette();
painter.setPen(pal.mid().color());
painter.drawLine(0, y, x, y);
painter.setPen(pal.base().color());
painter.drawPoint(x + 1, y);
painter.drawLine(0, y + 1, x + 1, y + 1);
}
Since this ruler could not be removed, I would suggest you to hide it.
The implementation of QWizardHeader::paintEvent
gives an idea of how to do that, i.e. by setting the color role used to paint the line, QPalette::Mid
, to the appropriate color, which blends with the background, QPalette::Base
.
Note: If this color role is used by any other item, its color would be affected as well.
Here is an example I have prepared for you of how the proposed solution could be implemented:
Substitute
for (auto *widget : this->findChildren<QWidget *>())
{
widget->setStyleSheet("background:none; border:none; margin:0; padding:0;");
}
with
QPalette p(palette());
p.setColor(QPalette::Mid, p.color(QPalette::Base));
setPalette(p);
The given example produces the following result: