QT sets the widget background image without affecting the background of other controls in the widget

First of all, let’s talk about the method. When adding a background image to a widget or frame or any other type of control, add the following code to the style sheet to specify a control and set its background.

类名 # 控件名
{
填充方式:图片路径
}

例如:
QWidget#Widget
{
    border-image: url(:/resource/bg2.png);
}
或者
QFrmae#frame
{
    border-image: url(:/resource/bg2.png);
}

If you simply change the style sheet without specifying a control, the background of other internal controls will also change.

Special reminder: class name# control name, the control name must be accurate, if you change the name of the widget to something else, then the control name here must be consistent.

Error demonstration:

As shown in the picture: the effect is very messy.

Correct demonstration:

Effect: only the background of the specified widget changes, and the background of the internal controls of the widget remains unchanged

Guess you like

Origin blog.csdn.net/weixin_55735677/article/details/129612500