Results 1 to 4 of 4

Thread: Building TabBar in QML - Loader doesn't show all the Rectangles

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Building TabBar in QML - Loader doesn't show all the Rectangles

    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Window 2.2
    3.  
    4. Window
    5. {
    6. visible: true
    7. height: 500
    8. width: 500
    9.  
    10. property VisualItemModel contentToBeShownOnTabClick : visualItemModelDemo
    11. property variant tabLabels : ["Navigation", "Payload", "System Control"]
    12.  
    13. VisualItemModel
    14. {
    15. id: visualItemModelDemo
    16.  
    17. Rectangle
    18. {
    19. id: navigationTab
    20. color: "green"
    21. height: 200
    22. width: 200
    23. }
    24. Rectangle
    25. {
    26. id: navigationTab1
    27. color: "darkgreen"
    28. height: 200
    29. width: 200
    30. }
    31. Rectangle
    32. {
    33. id: navigationTab2
    34. color: "lightgreen"
    35. height: 200
    36. width: 200
    37. }
    38. }
    39.  
    40. MainForm
    41. {
    42. Component
    43. {
    44. id: tabsOnBottomComponent
    45. Repeater
    46. {
    47. model: tabLabels
    48. // The Tabs
    49. Rectangle
    50. {
    51. id: tabsOnBottom
    52. // This anchoring places the tabs on the outer top of the parent rectangle.
    53. anchors.top: parent.bottom
    54. anchors.topMargin: 180
    55. color: "lightsteelblue"
    56. border.color: "steelblue"
    57. border.width: 2
    58. implicitWidth: Math.max ((labelTabsBottom.width + 4), 80)
    59. implicitHeight: 20
    60. radius: 2
    61. // Tabs Text/Label
    62. Text
    63. {
    64. id: labelTabsBottom
    65. anchors.centerIn: parent
    66. color: "white"
    67. rotation: 0
    68. // With reference to mode: tabLabels
    69. text: modelData
    70. font.pointSize: 11
    71. }
    72.  
    73. MouseArea
    74. {
    75. anchors.fill: parent
    76. onClicked: bottomTabClicked (index);
    77. }
    78. }
    79. }
    80. }
    81.  
    82.  
    83. Rectangle
    84. {
    85. // The things which get displayed on clicking of a tab will be shown in this rectangle.
    86. id: areaForTabContents
    87. border.color: "black"
    88. border.width: 10
    89. height: parent.height
    90. width : parent.width
    91. color : "pink"
    92.  
    93. // These are the tabs displayed in one row - horizontally.
    94. Row
    95. {
    96. id: horizontalTabs
    97.  
    98. Loader
    99. {
    100. anchors.fill: parent
    101. sourceComponent: tabsOnBottomComponent
    102. }
    103. }
    104. }
    105.  
    106. anchors.fill: parent
    107. }
    108. }
    To copy to clipboard, switch view to plain text mode 

    This gets shown as follows:
    now.png

    whereas I want it to see 3 rectangles there side by side.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Building TabBar in QML - Loader doesn't show all the Rectangles

    You anchor all elements of the repeater to the same position.

    Put the Repeater into a Column or ColumnLayout

    Cheers,
    _

  3. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Building TabBar in QML - Loader doesn't show all the Rectangles

    Repeater in the Loader and the Loader is in the Row. What point am I missing?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Building TabBar in QML - Loader doesn't show all the Rectangles

    The Row has a single element, the Loader.
    Usually a Row, Column or Grid is used when you have multiple child items and want them position automatically.

    What you want is to have the Repeater populate the Row, so the Row needs to be the parent of the Repeater.

    Cheers,
    _

Similar Threads

  1. Qt.inputMethod.show () doesn't show any keyboard
    By TheIndependentAquarius in forum Qt Quick
    Replies: 0
    Last Post: 23rd February 2015, 10:45
  2. Replies: 4
    Last Post: 18th October 2013, 17:15
  3. Transparency doesn't work in building Qt from sources
    By AspiringEngineer in forum Qt Programming
    Replies: 0
    Last Post: 18th June 2013, 14:31
  4. QGraphicsTextItem doesn't show up
    By chapu in forum Qt Programming
    Replies: 6
    Last Post: 12th July 2010, 00:48
  5. show Tabbar only if there are more than 1 tabs.
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 23rd September 2007, 20:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.