Important: Please read the Qt Code of Conduct -

overwriting inherited stylesheet properties

  • I just started learning Qt. It seems that changing inherited stylesheet properties sometimes does not work. The following is the implementation source file for Window class. I have two pointers to QLabel, plabel0 and plabel1, declared in Window.h. plabel0 can change the inherited font size from 40 to 10. However plabel1 cannot change the border width to 0px. I've also tried to set border:none and border-style: 0px for plabel1, but none of these work. I'm using Qt version 5.11.3.

    Window::Window(QWidget * parent)
        : QWidget(parent)
        setFixedSize(400, 400);
        setStyleSheet("background-color: rgb(50,50,50);;");
        setStyleSheet("QLabel {"
                      "font-size: 40px;"
                      "border: 5px solid white};");
        plabel0 = new QLabel("ABC", this);
        plabel0->setGeometry(10, 10, 50, 50);
        plabel0->setStyleSheet("font-size: 10px");  // OK
        plabel1 = new QLabel("DEF", this);
        plabel1->setGeometry(100, 10, 50, 50);
        plabel1->setStyleSheet("border: 0px"); // does not work

  • Well, works on my 5.12.7.
    How about changing that to:

    "border-width: 0px"

  • I tried that too. Doesn't work.

Log in to reply