标题:不规则边缘背景图片,透明部分有杂色
作者:yangshen1990
日期:2016-06-22 07:35
内容:
程序运行环境为arm芯片,Ubuntu系统
采用setAttribute(Qt::WA_TranslucentBackground, true)的方式设置界面属性
重载paintEvent加载背景图片
void advancedSet::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap(0,0,width(),height(),QPixmap(":/images/backgroud.png"));
}
背景图片为边缘带阴影png图片,当尺寸较小时,如352*288,边缘半透明阴影那块有杂色

但是当分辨率较大时,当尺寸较大时,如1920*1080,显示就正常了

请问有没有大神知道这是显示芯片原因、qt设置问题 ..
#1 [leonchiong 06-22 07:58]
你用QSS来贴背景图这个问题应该就能解决了
#2 回 leonchiong 的帖子 [yangshen1990 06-22 20:00]
leonchiong:你用QSS来贴背景图 这个问题应该就能解决了 (2016-06-22 07:58)
是用border-image吗,这个貌似可以解决尺寸和底图大小不匹配的问题,但现在底图和窗体尺寸是一样的,有杂色的部分是图片阴影部分。
还有一种情况是窗体大小300*300,只有中间20*20的部分有一张小图,其余部分都是设置成透明的,现在透明的部分全是杂色,是不是和窗体透明的设置方式有关系?
#3 [leonchiong 06-23 07:52]
曾经遇到过在win7上做的窗体透明程序 在XP上运行出现杂色或黑块的现象
我目前使用的透明方法也是跟论坛里的朋友学来的
就是使用QPainter来贴一张png透明图片 效果还不错
#4 回 leonchiong 的帖子 [yangshen1990 06-23 20:36]
leonchiong:曾经遇到过在win7上做的窗体透明程序 在XP上运行出现杂色或黑块的现象
我目前使用的透明方法也是跟论坛里的朋友学来的
就是使用QPainter来贴一张png透明图片 效果还不错
....... (2016-06-23 07:52)
我用的就是qpainter,贴边缘是阴影半透明的png图,就是1楼的那种方法,和您的方法一样吗?
#5 [leonchiong 06-27 08:16]
QPixmapmShadow(":/images/window/window_shadow.png");
this->setAttribute(Qt::WA_TranslucentBackground);
void FWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QRect bottom(5, 136, 200, 7);
QRect top(5, 0, 200, 3);
QRect left(0, 3, 5, 133);
QRect right(205, 3, 5, 133);
QRect topRight(205, 0, 5, 3);
QRect topLeft(0, 0, 5, 3);
QRect bottomLeft(0, 136, 5, 7);
QRect bottomRight(205, 136, 5, 7);
QRect tBottom(5, this->height() - 7, this->width() - 10, 7);
QRect tTop(5, 0, this->width() - 10, 3);
QRect tLeft(0, 3, 5, this->height() - 10);
QRect tRight(this->width() - 5, 3, 5, this->height() - 10);
QRect tTopLeft(0, 0, 5, 3);
QRect tTopRight(this->width() - 5, 0, 5, 3);
QRect tBottomLeft(0, this->height() - 7, 5, 7);
QRect tBottomRight(this->width() - 5, this->height() - 7, 5, 7);
painter.drawPixmap(tBottom, mShadow, bottom);
painter.drawPixmap(tTop, mShadow, top);
painter.drawPixmap(tLeft, mShadow, left);
painter.drawPixmap(tRight, mShadow, right);
painter.drawPixmap(tTopRight, mShadow, topRight);
painter.drawPixmap(tTopLeft, mShadow, topLeft);
painter.drawPixmap(tBottomLeft, mShadow, bottomLeft);
painter.drawPixmap(tBottomRight, mShadow, bottomRight);
}
贴边框的就用到这三段