zoukankan      html  css  js  c++  java
  • Qt 通过绘画设置边框阴影

    [cpp] view plain copy
     
    1. 首先widget设置  
    2.     setWindowFlags(Qt::FramelessWindowHint);  
    3.     setAttribute(Qt::WA_TranslucentBackground, true);  

    [cpp] view plain copy
     
    1. 然后重载paintevent  
    2. void ShadowMethod::paintEvent(QPaintEvent *event)  
    3. {  
    4.     QPainterPath path;  
    5.      path.setFillRule(Qt::WindingFill);  
    6.      path.addRect(10, 10, this->width()-20, this->height()-20);  
    7.   
    8.      QPainter painter(this);  
    9.      painter.setRenderHint(QPainter::Antialiasing, true);  
    10.      painter.fillPath(path, QBrush(Qt::white));  
    11.   
    12.      QColor color(92,93,95,50);  
    13.      int arr[10] = {150,120,80,50,40,30,20,10,5,5};  
    14.      for(int i=0; i<10; i++)  
    15.      {  
    16.          QPainterPath path;  
    17.          path.setFillRule(Qt::WindingFill);  
    18.          if(i == 5)  
    19.              path.addRect(10-i-1, 10-i-1, this->width()-(10-i)*2, this->height()-(10-i)*2);  
    20.          else  
    21.             path.addRoundedRect(10-i-1, 10-i-1, this->width()-(10-i)*2, this->height()-(10-i)*2,2,2);  
    22.   
    23.          color.setAlpha(arr[i]);  
    24.          painter.setPen(color);  
    25.          painter.drawPath(path);  
    26.   
    27.      }  
    28.   
    29.   
    30. }  
    [cpp] view plain copy
     
    1.   
    [cpp] view plain copy
     
    1. 效果图:  
    [cpp] view plain copy
     
    1. <img src="http://img.blog.csdn.net/20171011165958714?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHpwYmxvZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">  
     
    https://blog.csdn.net/xzpblog/article/details/78205710
  • 相关阅读:
    Leetcode95. Unique Binary Search Trees II不同的二叉搜索树2
    Leetcode134. Gas Station加油站
    Leetcode152. Maximum Product Subarray乘积的最大子序列
    C#扩展方法
    Lua语言入门
    Docker命令
    SpringBoot-配置文件属性注入-3种方式
    从零开始学Linux系统(五)用户管理和权限管理
    MyCat学习笔记
    kafka-zk-安装测试初体验
  • 原文地址:https://www.cnblogs.com/findumars/p/8627697.html
Copyright © 2011-2022 走看看