zoukankan      html  css  js  c++  java
  • Qt之再谈窗体阴影

        前面就窗口阴影已经写过一篇博客,使用九宫格的思路实现的,在我看来,凡是用程序能实现的尽量不要使用图片代替(在保证效率的前提下),今天再次分享关于我的一些小见解!

        先看效果:
     

        窗口阴影任意调节,包括阴影像素、是否圆角等。
        直接上代码:

    void DropShadowWidget::paintEvent(QPaintEvent *event)
    {
        QPainterPath path;
        path.setFillRule(Qt::WindingFill);
        path.addRect(10, 10, this->width()-20, this->height()-20);

        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing, true);
        painter.fillPath(path, QBrush(Qt::white));

        QColor color(0, 0, 0, 50);
        for(int i=0; i<10; i++)
        {
            QPainterPath path;
            path.setFillRule(Qt::WindingFill);
            path.addRect(10-i, 10-i, this->width()-(10-i)*2, this->height()-(10-i)*2);
            color.setAlpha(150 - qSqrt(i)*50);
            painter.setPen(color);
            painter.drawPath(path);
        }
    }
        记得加上这行代码: setAttribute(Qt::WA_TranslucentBackground)。保证不被绘制上的部分透明,关于这行代码有些副作用,比如:最小化后窗体子组件失去焦点等问题。当然,也许是我没搞明白,还有待高见!
  • 相关阅读:
    HashMap源码分析
    Vector和Stack源码分析/List集合的总结
    LinkedList源码分析
    ArrayList源码分析
    第三章 数据链路层(三)
    Java常考面试题(五)
    hibernate(一) 第一个hibernate工程
    回想过去,展望未来
    “Cannot load php5apache2_4.dll into server”问题的解决方法
    win7下80端口被(Pid=4)占用的解决方法
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3215199.html
Copyright © 2011-2022 走看看