Как сбросить таблицу стилей дочернего элемента в таблицу стилей Qt по умолчанию при изменении «таблицы стилей дочернего родителя»? - PullRequest
0 голосов
/ 24 октября 2018

Когда я изменяю таблицу стилей объекта, изменяется и таблица стилей его потомка.как я могу сбросить дочернюю таблицу стилей на стиль Qt по умолчанию?для проверки этого я использую следующий код:

в заголовочном файле:

#include "ui_QtGuiApplication.h"
#include <QGraphicsView>
#include <QtWidgets/QPushButton>

class QtGuiApplication : public QMainWindow
{
    Q_OBJECT

public:
    QtGuiApplication(QWidget *parent = Q_NULLPTR);


private:
    Ui::QtGuiApplicationClass ui;
    QGraphicsView* qGraph;
    QGraphicsScene* scene;

};

в исходном файле:

#include "QtGuiApplication.h"

QtGuiApplication::QtGuiApplication(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    // Change centralWidget stylesheet      
    ui.centralWidget->setStyleSheet(
        "background:qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 : 1,\
        stop : 0  rgb(216, 0, 0), stop : 0.4 rgb(155, 0, 0),\
        stop : 0.4 rgb(155, 0, 0), stop : 1.0 rgb(216, 0, 0));");


    // creat a QGraphicsView an add it to centralWidget
    qGraph = new QGraphicsView(ui.centralWidget);
    qGraph->setGeometry(QRect(70, 30, 300, 300));
    scene = new QGraphicsScene(qGraph);
    scene->setSceneRect(0, 0, 300, 300);
    qGraph->setScene(scene);
    qGraph->show();

    // creat a push button and add it in to centralWidget
    QPushButton* btn_Ok = new QPushButton(ui.centralWidget);
    btn_Ok->setGeometry(QRect(340, 340, 75, 23));
    btn_Ok->setText("Ok");
    //below code doesn't work 
    btn_Ok->setStyleSheet("");
    btn_Ok->setStyleSheet(styleSheet());

}
...