Qt中实现图片透明度设置与显示

您所在的位置:网站首页 qt设置界面透明度 Qt中实现图片透明度设置与显示

Qt中实现图片透明度设置与显示

2023-12-03 21:59| 来源: 网络整理| 查看: 265

在使用QGraphicsScene过程中,想要实现背景和前景图层叠加显示,需要设置对应层绘图的透明度的设置。采用重写drawBackground(QPainter *painter, const QRectF &rect)和drawForeground(QPainter *painter, const QRectF &rect)事件实现。类似的,QPainter的setOpacity()方法可以在相关控件绘制图片时使用,设置图片透明度。

drawForeground(QPainter *painter, const QRectF &rect) { QPixmap foreImg; foreImg.load("C:/Users/Desktop/fengjing1.jpg"); if (!foreImg.isNull()) { painter->setOpacity(0.4);//透明度设置 painter->drawPixmap(int(sceneRect().left()), int(sceneRect().top()), foreImg); } } drawBackground(QPainter *painter, const QRectF &rect) { QPixmap foreImg; foreImg.load("C:/Users/Desktop/fengjing2.jpg"); if (!foreImg.isNull()) { painter->setOpacity(0.9);//透明度设置 painter->drawPixmap(int(sceneRect().left()), int(sceneRect().top()), foreImg); } }



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3