Important: Please read the 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 };


    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


    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.


Log in to reply