CQGUI框架之阴影圆角窗口实现

大家好,我是IT文艺男,来自一线大厂的一线程序员

今天给大家讲解基于C++/Qt的CQGUI框架的阴影圆角窗口实现,实现效果如下图所示::

CQGUI开发环境::

  • Microsoft Visual Studio 2019
  • Qt5.15.1

步骤如下::

一、继承关系

class LoginPanel : public QDialog

二、窗口属性

setAttribute(Qt::WA_TranslucentBackground); //设置顶层面板背景透明
setWindowFlags(Qt::FramelessWindowHint); //设置无边框
setContentsMargins(10, 10, 10, 10);

Qt::WA_TranslucentBackground Indicates that the widget should have a translucent background, i.e., any non-opaque regions of the widgets will be translucent because the widget will have an alpha channel. Setting this flag causes WA_NoSystemBackground to be set. On Windows the widget also needs the Qt::FramelessWindowHint window flag to be set. This flag is set or cleared by the widget's author.

三、设置阴影效果

auto *defaultShadow = new QGraphicsDropShadowEffect();
defaultShadow->setBlurRadius(10.0);
defaultShadow->setColor(QColor(0, 0, 0, 160));
defaultShadow->setOffset(0, 0);
_loginMainFrm->setGraphicsEffect(defaultShadow);

四、设置样式

QFrame#loginMainFrm>QFrame#leftFrame{
background:rgba(255,255,255,0.9);
border-top-left-radius:6px;
border-top-right-radius:0px;
border-bottom-right-radius:0px;
border-bottom-left-radius:6px;
}

五、事件响应

protected:
void mousePressEvent(QMouseEvent *e) override ;
void mouseReleaseEvent(QMouseEvent *e) override ;
void mouseMoveEvent(QMouseEvent *e) override ;
void closeEvent(QCloseEvent *e) override ;
bool event(QEvent* e) override ;
protected:
bool eventFilter(QObject* o, QEvent* e) override;

今天就讲解到这里,按步骤进行梳理,过程很清晰; 更详细的代码分析与讲解,请关注微信公众号(itwenyinan),观看对应的的视频版讲解;谢谢

最新文章

  1. Newtonsoft.Json
  2. arraylist与linkedlist的区别与性能测试
  3. Adding Value To Combo List at Runtime in Oracle Forms
  4. grunt下cssmin的配置参数
  5. HDU 2985 Another lottery(坑题)
  6. [品质生活] 舒适 Schick HYDRO 5剃须刀
  7. Memcached帮助类
  8. maven引用net.sf.json-lib
  9. python基础—购物车小程序练习
  10. linux的一些基本命令
  11. fiddler抓取手机上https数据失败,全部显示“Tunnel to......443”解决办法
  12. 在windows 10下使用docker
  13. Memento Mori (二维前缀和 + 枚举剪枝)
  14. c++ String去除头尾空格
  15. Jmeter之集合点与关联
  16. 搜狐视频Redis私有云平台CacheCloud
  17. [转]Python与设计模式
  18. python-生成器、迭代器、装饰器
  19. AtomicReference与volatile的区别
  20. 百度地图label样式修正

热门文章

  1. TypeScript constructor public cause duplicate bug
  2. svn conflict & svn cleanup
  3. npm published cli package's default install missing the `-g` flag
  4. learning free programming resources form top university of the world
  5. fetch & form-data & upload & image file
  6. Captain technology INC:高性能电池助力新能源车企销量暴涨
  7. WebRTC 系列之音频会话管理
  8. js合并字符串的3种方法和效率
  9. python的基本运算符
  10. Redis 使用入门