Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1040460
  • 博文数量: 155
  • 博客积分: 5339
  • 博客等级: 大校
  • 技术积分: 1436
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-10 21:41
文章分类

全部博文(155)

文章存档

2016年(3)

2015年(7)

2014年(3)

2013年(1)

2012年(8)

2011年(5)

2010年(1)

2009年(5)

2008年(4)

2007年(26)

2006年(46)

2005年(46)

分类: C/C++

2014-11-17 18:04:30

最近饶有兴趣的研究了下qt,参考了很多的博客和论坛资料,实现了一个无边框、带阴影的窗体。
主体界面使用的是QT 5.3 Demo StocQt:


其实需要改动的点并不多:
1.main.cpp,原来例子中是一个宏,我拿了出来,添加了

点击(此处)折叠或打开

  1. view.setFlags(Qt::Window|Qt::FramelessWindowHint);//设置为无边框

  2. view.setColor(QColor(Qt::transparent));//窗体设置为透明

  3. view.rootContext()->setContextProperty("window",&view);//将窗口参数传入qml脚本,参数名可自定义

2.stockqt.qml,在主题窗口外层添加了一个阴影层,窗体添加阴影可参考:

点击(此处)折叠或打开

  1. Rectangle {//最底层透明图层
  2. width: 1000;
  3. height: 700;
  4. color: "transparent"
  5. property int listViewActive: 0
  6. Item {//主体窗口
  7. id: container;
  8. anchors.centerIn: parent;
  9. width: parent.width;
  10. height: parent.height;
  11. Rectangle {
  12. id: mainRect
  13. width: container.width-(2*rectShadow.radius);
  14. height: container.height - (2*rectShadow.radius);
  15. anchors.centerIn: parent;
  16. //以下省略
  17. }
  18. }
  19. DropShadow {//绘制阴影
  20. id: rectShadow;
  21. anchors.fill: source
  22. cached: true;
  23. horizontalOffset: 0;
  24. verticalOffset: 3;
  25. radius: 8.0;
  26. samples: 16;
  27. color: "#80000000";
  28. smooth: true;
  29. source: container;
  30. }
  31. }
3.为ListView添加间隔:

点击(此处)折叠或打开

  1. spacing:rectShadow.radius
4.从其他代码借鉴过来的最小化和关闭按钮:

点击(此处)折叠或打开

  1. Item {//最小化按钮、关闭按钮
  2.      anchors.right: banner.right
  3.      anchors.rightMargin: 60
  4.      SysBtnGroup
  5.      {
  6.          id: sysbtngrp

  7.          onMin: window.showMinimized()
  8.          onClose: window.close()
  9.       }
  10.       }
下面是完成的项目文件:
androidexam2.rar




阅读(9831) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~