Using an alpha transparent mask on a QWidget?

后端 未结 1 401
失恋的感觉
失恋的感觉 2021-01-21 19:37

Is it possible to assign an alpha-transparent mask to a QWidget? I know how to set a mask using setMask but it seems it only supports black&white masks. Is it p

相关标签:
1条回答
  • 2021-01-21 20:00

    I think your best route is in QPainter's composition modes.

    For example:

    QPixmap PixmapToBeMasked(Size);
    PixmapToBeMasked.fill(QColor(255, 255, 255, 120));
    
    QPixmap Mask = DoSomethingToGetAMask();
    
    QPainter Painter(&PixmapToBeMasked);
    Painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
    Painter.drawPixmap(0, 0, Mask.width(), Mask.height(), Mask);
    

    That will handle drawing your widget nicely. If you still need to mask mouse events you might need to do some extra work though.

    0 讨论(0)
提交回复
热议问题