name_label->setStyleSheet("background-image:url(:/album/album_topbar2);\
font-family: Noto Sans SC;\
font-style: normal;\
font-weight: normal;\
font-size: 30px;\
line-height: 43px;\
color: #FFFFFF;}");
remark_button->setStyleSheet("QPushButton{border-image: url(:/album/album_remark_bg);\
font-family: Noto Sans SC;\
font-style: normal;\
font-weight: normal;\
font-size: 24px;\
line-height: 35px;\
text-align: left bottom;\
padding-left: 20px; \
padding-bottom: 20px;\
color: rgba(255, 255, 255, 0.7);}");
背景应该是两个半透明渐变色块,但实际上此设置未生效。父窗口重写了paintEvent如下:
void ShowWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QImage * image = currentImage;
const qreal iw = image->width();
const qreal ih = image->height();
const qreal wh = height();
const qreal ww = width();
painter.translate(ww/2, wh/2);
painter.translate(-iw/2, -ih/2);
painter.drawImage(0,0,*image);
}
实际结果:
预期结果:
emmm 后来发现样式表生效了,只是生效区域显示空白,不清楚是label、button部件自动加了底色,还是qwidget绘制图片的时候认为此处被遮挡,没绘制,不知道有大佬看到帮忙解惑没
最后直接把图片重绘在图片里了
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(0, 48, name_bg);
painter.drawImage(0, 900, remark_bg);