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

时间:2016-06-10 22:57:49   收藏:0   阅读:1070

在派生类中重载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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!