服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C/C++ - Qt中CQGUI框架之阴影圆角窗口实现

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

2021-10-28 14:46IT文艺男 C/C++

这篇文章主要介绍了Qt中CQGUI框架之阴影圆角窗口实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

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

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

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

CQGUI开发环境::

  • Microsoft Visual Studio 2019
  • Qt5.15.1

步骤如下:

一、继承关系

?
1
class LoginPanel : public QDialog

二、窗口属性

?
1
2
3
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.

三、设置阴影效果

?
1
2
3
4
5
auto *defaultShadow = new QGraphicsDropShadowEffect();
defaultShadow->setBlurRadius(10.0);
defaultShadow->setColor(QColor(0, 0, 0, 160));
defaultShadow->setOffset(0, 0);
_loginMainFrm->setGraphicsEffect(defaultShadow);

四、设置样式

?
1
2
3
4
5
6
7
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;
}

五、事件响应

?
1
2
3
4
5
6
7
8
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;

到此这篇关于Qt中CQGUI框架之阴影圆角窗口实现的文章就介绍到这了,更多相关CQGUI阴影圆角窗口内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.cnblogs.com/appsucc/p/14587599.html

延伸 · 阅读

精彩推荐