转换用作QGraphicsOpacityEffect的QPixmap

问题描述

我有三张图像,其中两张是全彩色并覆盖的(即一张在另一张上面,所以您只能看到一张在上面),第三张有黑色的部分和透明的部分,用作使用QGraphicsOpacityEffect()的不透明蒙版,并将其应用于用于显示顶部图像的QLabel。我想随时间移动用作不透明蒙版的图像,以便根据不透明蒙版图像的位置显示顶部和底部图像的不同部分,但我似乎无法使其正常工作:

Qpixmap mask_img("path to mask image");
QGraphicsOpacityEffect *opacity_effect = new QGraphicsopacityEffect();
opacity_effect->setopacityMask(mask_img.scaled(1800,310);

QImage top_img("path to top image");
QLabel *top_img_label = new QLabel
top_img_label->setGraphicsEffect(opacity_effect);
top_img_label->setAlignment(Qt::AlignCenter);
top_img_label->setpixmap(Qpixmap::fromImage(top_img).scaled(900,310);

QImage bottom_img("path to bottom image");
QLabel *bottom_img_label = new QLabel
bottom_img_label->setGraphicsEffect(opacity_effect);
bottom_img_label->setAlignment(Qt::AlignCenter);
bottom_img_label->setpixmap(Qpixmap::fromImage(bottom_img).scaled(900,310);

这确实有效(即,它显示底部图像的那些部分被应用于顶部图像的蒙版图像的透明部分“未遮盖”),但是我也想随着时间的推移移动蒙版

我尝试应用.transformed(QTransform()。translate(x_move,y_move)),但这似乎没有用。另外,如果我缩放蒙版图像以使其小于两个图像,则将重复蒙版

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)