如何删除QWizard中的水平线? [英] How to remove the horizontal line in a QWizard?

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

问题描述

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

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

我尝试递归浏览所有小部件并将其边框设置为none,但是似乎没有任何小部件具有此边框.

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

有可能吗?

推荐答案

原因

此标尺 QWizardRuler *bottomRuler 不受样式表的影响,因为 QWizardRuler继承了QWizardHeader ,并且该线在

Cause

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

解决方案

由于无法移除此标尺,因此建议您将其隐藏.

Solution

Since this ruler could not be removed, I would suggest you to hide it.

QWizardHeader::paintEvent的实现给出了如何执行此操作的想法,即通过设置颜色角色用于将线条QPalette::Mid绘制为适当的颜色,并与背景QPalette::Base融合.

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:

替代

for (auto *widget : this->findChildren<QWidget *>())
{
    widget->setStyleSheet("background:none; border:none; margin:0; padding:0;");
}

使用

QPalette p(palette());

p.setColor(QPalette::Mid, p.color(QPalette::Base));

setPalette(p);

结果

给定的示例将产生以下结果:

Result

The given example produces the following result:

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

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