问题描述:
在QWidget上add 一个QLabel,但是死活不生效
原因:
c++ 主程序如下:
QWidget* LOGO = new QWidget(logo_wnd);
LOGO->setFixedSize(logo_width, 41);
LOGO->setObjectName("TittltLogo");
QVBoxLayout* title_layout = new QVBoxLayout(LOGO);
title_layout->setMargin(0);
title_layout->setContentsMargins(QMargins(0, 0, 0, 0));
title_layout->setSpacing(0);
LOGO->setLayout(title_layout);
QLabel* titleLabel = new QLabel(LOGO);
titleLabel->setObjectName("TitleLogoLabel"); titleLabel->setAlignment(Qt::AlignCenter);
titleLabel->setText(LanguageReader::GetInstance().GetLanguageText(MAIN_FORM, "SystemTitle"));
titleLabel->adjustSize();
title_layout->addWidget(titleLabel);
qss如下:QWidget 的qss设置在QLabel 的前边
QWidget#TittltLogo
{
background-color: transparent;
border: none;
//background-image: url(./Source/TittleText.png);
}
QLabel#TitleLogoLabel
{
background-color: transparent;
font-family: 'Microsoft YaHei';font-size: 20px; font-style: normal; font-weight: 600; color:#DCDCDC;
border: none;
}
qss: 需要将 位置互换
QLabel#TitleLogoLabel
{
background-color: transparent;
font-family: 'Microsoft YaHei';font-size: 20px; font-style: normal; font-weight: 600; color:#DCDCDC;
border: none;
}
QWidget#TittltLogo
{
background-color: transparent;
border: none;
//background-image: url(./Source/TittleText.png);
}
不太明白....................有缘人解答下为什么?
问题补充:2024.11.15
如果按上述修改,还是会有问题,会影响原来的其它控件的qss设置,如下图所示:
将QWidget的qss注释即可:正常的应该是
问题解决了,真相大白: