How do I style a Qt Widget not its children with stylesheets?

前端 未结 2 782
一生所求
一生所求 2020-12-08 06:14

I have a:

class Box : public QWidget

and it has

this->setLayout(new QGridLayout(this));

I tried doin

2条回答
  •  遥遥无期
    2020-12-08 06:40

    You need to identify the object class and instance, like in regular CSS.

    QWidget#BoxName
    {
        border-radius: 5px;
        border: 1px solid black;
        border: 2px groove gray;
    }
    

    This is the same answer as here: Get variable name of Qt Widget (for use in Stylesheet)?

    box->setStyleSheet(QString::fromUtf8("QWidget#box\n"
    "{\n"
    "    border-radius: 5px;\n"
    "    border: 1px solid black;\n"
    "    border: 2px groove gray;\n"
    "}\n"
    ""));
    

提交回复
热议问题