• 4818阅读
  • 5回复

[提问]不规则边缘背景图片,透明部分有杂色 [复制链接]

上一主题 下一主题
离线yangshen1990
 

只看楼主 倒序阅读 楼主  发表于: 2016-06-22
回复本帖可获得10RMB金钱奖励!
每人最多可获奖1次,奖池剩余10RMB金钱 (中奖几率10%)
程序运行环境为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设置问题还是什么情况?
离线leonchiong

只看该作者 1楼 发表于: 2016-06-22
你用QSS来贴背景图  这个问题应该就能解决了
离线yangshen1990

只看该作者 2楼 发表于: 2016-06-22
回 leonchiong 的帖子
leonchiong:你用QSS来贴背景图  这个问题应该就能解决了 (2016-06-22 07:58) 

是用border-image吗,这个貌似可以解决尺寸和底图大小不匹配的问题,但现在底图和窗体尺寸是一样的,有杂色的部分是图片阴影部分。
还有一种情况是窗体大小300*300,只有中间20*20的部分有一张小图,其余部分都是设置成透明的,现在透明的部分全是杂色,是不是和窗体透明的设置方式有关系?
离线leonchiong

只看该作者 3楼 发表于: 2016-06-23
曾经遇到过在win7上做的窗体透明程序 在XP上运行出现杂色或黑块的现象

我目前使用的透明方法也是跟论坛里的朋友学来的
就是使用QPainter来贴一张png透明图片 效果还不错

离线yangshen1990

只看该作者 4楼 发表于: 2016-06-23
回 leonchiong 的帖子
leonchiong:曾经遇到过在win7上做的窗体透明程序 在XP上运行出现杂色或黑块的现象
我目前使用的透明方法也是跟论坛里的朋友学来的
就是使用QPainter来贴一张png透明图片 效果还不错
....... (2016-06-23 07:52) 

我用的就是qpainter,贴边缘是阴影半透明的png图,就是1楼的那种方法,和您的方法一样吗?
离线leonchiong

只看该作者 5楼 发表于: 2016-06-27
QPixmap  mShadow(":/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);
}

贴边框的就用到这三段
快速回复
限100 字节
 
上一个 下一个