QT绘制半透明窗体(改写paintEvent,超级简单)

在派生类中重载QDialog的void paintEvent(QPaintEvent *)事件,在这个函数中加入以下代码

QPainter painter(this);
    QLinearGradient grad(0, 0, width(), height());
    QGradientStops gs;
    
    gs << QGradientStop(0.0, QColor(0, 0, 0 , 100))
        << QGradientStop(0.5, QColor(0, 0, 0, 100))
        << QGradientStop(1.0, QColor(0, 0, 0, 100));
    grad.setStops(gs);
    painter.fillRect(0, 0, width(), height(), grad);

http://blog.csdn.net/itjobtxq/article/details/8766721

原文地址:https://www.cnblogs.com/findumars/p/5574325.html