In the custom control, using QSS to accurately set the properties of the QPushButon control object does not take effect.

There are similar usages in QSS:

QPushButton#minBtn {
border-radius:2px;
border-image:url(:/images/btn_mini_normal.png);
}

#minBtn is the property of precisely specifying the button control whose objectName is minBtn, and it has no effect on other button controls.

But it should be noted that minBtn is not the name of the QPushButton object you defined in the class, but the name specified by QSS using the objectName() interface. For example:

class XWidget : public QWidget {
  Q_OBJECT
 public:
  explicit XWidget(QWidget *parent = nullptr);
private:
   QPushButton *button;
 };

In this object, a variable named button of QPushButton is defined. If the button's properties are set in QSS with the name of button, it will not take effect. Because QSS doesn't even know about this control. To let QSS know that there is this control, you need to specify it with setObjectName().

button->setObjectName("minBtn");

Then use the name minBtn in QSS to specify the setting button properties to take effect.

Guess you like

Origin blog.csdn.net/VOlsenBerg/article/details/112979276