找回密码
 立即注册
Qt开源社区 门户 查看内容

兼容Qt4/Qt5版本Qml控件Calendar

2019-8-11 10:28| 发布者: admin| 查看: 1307| 评论: 0

摘要: 通过点击日历控件区域,选择日期的Qml组件。Calendar备注导入方法文件导入兼容性QtQuick1.x与QtQuick2.x继承GridView属性信号:signal clicked(variant date): 在日历中的有效日期上单击鼠标时发出,date是鼠标被单 ...

通过点击日历控件区域,选择日期的Qml组件。
Calendar备注
导入方法文件导入
兼容性QtQuick1.x与 QtQuick2.x
继承GridView



属性

信号:

  • signal clicked(variant date) : 在日历中的有效日期上单击鼠标时发出, date是鼠标被单击的日期。
方法:

  • functiontoday() :重定位到当天日期
  • functiongetDate() : 获取日历当前日期

  • functionsetDate(date) : 设置日历的日期

示例


  1. Calendar{

  2. width:600; height:480

  3. }



部分源码预览


  1. /**

  2. * @brief 在日历中的有效日期上单击鼠标时发出。

  3. * @param date: 鼠标被单击的日期。

  4. */

  5. signal clicked(variant date)


  6. /**

  7. * @brief 重定位到当天日期

  8. */

  9. function today(){

  10. var today =newDate()

  11. setDate(today)

  12. }


  13. /**

  14. * @brief 获取日历当前日期

  15. */

  16. function getDate(){

  17. return privateVar.getYMD(root.currentIndex)

  18. }


  19. /**

  20. * @brief 设置日历的日期

  21. */

  22. function setDate(date){

  23. privateVar.monthAndYearNumber =[date.getMonth()+1, date.getFullYear()]

  24. root.currentIndex = privateVar.getIndexByDate(date.getDate(), date.getMonth()+1, date.getFullYear())


  25. /* 更新日期任务列表 */

  26. __setNoteDates(privateVar.noteDates)

  27. }


  28. Item{

  29. id: weekItem

  30. width: root.width; height: root.height/13

  31. Repeater{

  32. model:["日","一","二","三","四","五","六"]

  33. Item{

  34. x: index * width

  35. width: root.cellWidth; height: weekItem.height


  36. Text{

  37. anchors.centerIn: parent

  38. text: model.modelData

  39. font.pixelSize: dpW(14)

  40. color:"#666666"

  41. }

  42. }

  43. }

  44. }

关于


  • 文章首发于公众号Qt君
  • 源码地址:

  1. https://github.com/QtComponent/Calendar

  • 最新源码下载地址

  1. https://github.com/QtComponent/Calendar/archive/master.zip

  • 相关应用: 安卓日历

  1. https://github.com/aeagean/Calendar




----------------------------------------------------------------------------------------------------------------------
我们尊重原创,也注重分享,文章来源于微信公众号:Qt君,建议关注公众号查看原文。如若侵权请联系qter@qter.org。
----------------------------------------------------------------------------------------------------------------------

鲜花

握手

雷人

路过

鸡蛋

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了