Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Adding an opacity gradient to a QVideoPlayer mask



  • Hello,

    I am generating a mask from an image file with a background alpha channel and applying it to a QVideoWidget :

    QString mask_path = { "mask.png" };
    QPixmap mask_map = { mask_path };
    videoWidget->setMask(mask_map.mask());
    

    qt_mask.png

    I would like there to be a smooth gradient at the outer edges of the mask, going from invisible to visible gradually.

    Is there a way to accomplish this using QLinearGradient or perhaps just by using an image editor? Also I realize I can pass a QRegion to setMask() instead of a QBitmap, but I could not find a way to create a QRegion with an opacity gradient.

    Much appreciated.


  • Lifetime Qt Champion

    Hi,

    Shouldn't you compose a QPixmap with your original image and a QImage containing the gradient you want to achieve ?



  • Hi, I've seen your replies come up quite a lot when googling Qt issues, thanks for this reply and the others.

    As for this problem, it seems I was overcomplicating things. After looking at the composition modes example you linked, I realized I could simply superimpose a QLabel widget on a QVideoPlayer to accomplish what I want. It's simple enough to invert the source image's opacity in an exernal editor and add the custom gradients manually.

    Cheers!


Log in to reply