当前位置:   article > 正文

QML教程(八) 工具栏TabBar_qml tabbar

qml tabbar

目录

一、工具栏TabBar、TabButton

二、多页面滑动容器 SwipeView

三、页面指示器PageIndicator 

四、综合示例 


一、工具栏TabBar、TabButton

  1. import QtQuick 6.4
  2. import QtQuick.Controls 6.4
  3. Rectangle {
  4. width: 720
  5. height: 640
  6. TabBar{
  7. TabButton{text: "文件"}
  8. TabButton{text: "编辑"}
  9. TabButton{text: "视图"}
  10. TabButton{text: "工具"}
  11. }
  12. }

二、多页面滑动容器 SwipeView

  1. import QtQuick 6.4
  2. import QtQuick.Controls 6.4
  3. Rectangle {
  4. width: 452
  5. height: 638
  6. SwipeView {
  7. id: view
  8. anchors.fill: parent
  9. //第一页
  10. Image {
  11. id: firstPage
  12. smooth: true
  13. mipmap: true
  14. antialiasing: true
  15. fillMode: Image.PreserveAspectFit
  16. sourceSize.height: height
  17. source: "https://img1.doubanio.com/view/photo/l/public/p2717886028.webp"
  18. }
  19. //第二页
  20. Rectangle{
  21. id: secondPage
  22. Rectangle{
  23. width: parent.width
  24. height: parent.height/2
  25. color: 'red'
  26. }
  27. Rectangle{
  28. y: parent.height/2
  29. width: parent.width
  30. height: parent.height/2
  31. color: 'yellow'
  32. }
  33. }
  34. //第三页
  35. Item{
  36. id: thirdPage
  37. Button{
  38. x:100
  39. y:100
  40. width:200
  41. height:50
  42. text:qsTr("OK")
  43. }
  44. }
  45. //第四页
  46. Image {
  47. id:forthPage
  48. smooth:true
  49. mipmap:true
  50. antialiasing:true
  51. fillMode:Image.PreserveAspectFit
  52. sourceSize.height: height
  53. source:"https://img1.doubanio.com/view/photo/l/public/p2717883198.webp"
  54. }
  55. }
  56. }

三、页面指示器PageIndicator 

  1. import QtQuick 6.4
  2. import QtQuick.Controls 6.4
  3. Rectangle {
  4. width: 452
  5. height: 638
  6. PageIndicator {
  7. id: indicator
  8. //页数
  9. count: 3
  10. //当前页码
  11. currentIndex: 0
  12. }
  13. }

四、综合示例 

  1. import QtQuick 6.4
  2. import QtQuick.Controls 6.4
  3. Rectangle {
  4. width: 720
  5. height: 640
  6. //工具栏,点击或上下左右键切换
  7. TabBar{
  8. id:tabBar
  9. TabButton{text: "文件"}
  10. TabButton{text: "编辑"}
  11. TabButton{text: "视图"}
  12. TabButton{text: "工具"}
  13. }
  14. // 多页面容器,鼠标或手势滑动切换
  15. SwipeView{
  16. id:view
  17. currentIndex: tabBar.currentIndex
  18. anchors.fill: parent
  19. //不要遮住工具栏
  20. anchors.topMargin: 50
  21. onCurrentIndexChanged: {
  22. tabBar.currentIndex=view.currentIndex
  23. indicator.currentIndex = currentIndex
  24. }
  25. //第一页
  26. Image {
  27. id: firstPage
  28. smooth: true
  29. mipmap: true
  30. antialiasing: true
  31. fillMode: Image.PreserveAspectFit
  32. sourceSize.height: height
  33. source: "https://img1.doubanio.com/view/photo/l/public/p2717886028.webp"
  34. }
  35. //第二页
  36. Image {
  37. id: secondPage
  38. smooth: true
  39. mipmap: true
  40. antialiasing: true
  41. fillMode: Image.PreserveAspectFit
  42. sourceSize.height: height
  43. source: "https://img1.doubanio.com/view/photo/l/public/p2717883198.webp"
  44. }
  45. //第三页
  46. Image {
  47. id: thirdPage
  48. smooth: true
  49. mipmap: true
  50. antialiasing: true
  51. fillMode: Image.PreserveAspectFit
  52. sourceSize.height: height
  53. source: "https://img2.doubanio.com/view/photo/l/public/p2873948072.webp"
  54. }
  55. //第三页
  56. Image {
  57. id: forthPage
  58. smooth: true
  59. mipmap: true
  60. antialiasing: true
  61. fillMode: Image.PreserveAspectFit
  62. sourceSize.height: height
  63. source: "https://img1.doubanio.com/view/photo/l/public/p2654487577.webp"
  64. }
  65. }
  66. // 底部页面指示器
  67. PageIndicator {
  68. id: indicator
  69. count: view.count
  70. currentIndex: view.currentIndex
  71. anchors.bottom: view.bottom
  72. anchors.horizontalCenter: parent.horizontalCenter
  73. }
  74. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/806094
推荐阅读
相关标签
  

闽ICP备14008679号