Results 1 to 3 of 3

Thread: How to manually specify spacing and positioning of items in GridLayout of QML?

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

    Default How to manually specify spacing and positioning of items in GridLayout of QML?

    * When I specify rows: 12, and columns: 5, how are the sizes of one row, and one column determined by Qt? Am I supposed to expect the whole main window to be divided into 12 rows and 5 columns?

    * In the following code, I have specified first rectangle in row 0 and second rectangle in row 2. I saw that Qt placed a random sized gap between the two buttons. How do I size the gap myself?

    * I notice that when I move one item, other items also get displaced. How to fiddle with one item without disturbing others?

    * Well, `Layout.alignment: Qt.AlignTop` did take things to the top corner, but is it necessary to use it? My rectangles where strangely placed before I used alignment.

    Qt Code:
    1. GridLayout
    2. {
    3. id: gridLayout
    4. rows: 12; columns: 5; rowSpacing: 0; columnSpacing: 0
    5.  
    6. property int secondScreenOptionsOpacity: 0
    7.  
    8. property int hmmiButtonRow: 0
    9. property int hmmiButtonCol: 0
    10.  
    11. Rectangle
    12. {
    13. id: hmmi; opacity: gridLayout.secondScreenOptionsOpacity
    14. Layout.row: gridLayout.hmmiButtonRow; Layout.column: gridLayout.hmmiButtonCol;
    15. height: 75; width: 150; color: "pink";
    16. Layout.alignment: Qt.AlignTop
    17. Text { text: "HMMI"; anchors.centerIn: parent }
    18. MouseArea {anchors.fill: parent; onClicked: mainScreenFunctionality.hmmiControlButton()}
    19. }
    20.  
    21. property int optionsButtonRow: 2
    22. property int optionsButtonCol: 0
    23.  
    24. Rectangle
    25. {
    26. id: optionsButton; opacity: gridLayout.secondScreenOptionsOpacity
    27. Layout.row: gridLayout.optionsButtonRow; Layout.column: gridLayout.optionsButtonCol;
    28. height: 75; width: 150; color: "red"
    29. Layout.alignment: Qt.AlignTop
    30. Text { text: "Options..."; anchors.centerIn: parent }
    31. MouseArea { anchors.fill: parent; onClicked: mainScreenFunctionality.optionsButton() }
    32. }
    33. ...
    34. ...
    35. }
    To copy to clipboard, switch view to plain text mode 

  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: How to manually specify spacing and positioning of items in GridLayout of QML?

    If you want the grid layout to fill the whole parent, anchor it with "fill: parent" to its parent.

    The height of a row is determined by the maximum height of all items in that row.
    Similarily, the width of a column is determined by the maximum wdith of all items in that column.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    jfinn88 (10th November 2016)

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

    Default Re: How to manually specify spacing and positioning of items in GridLayout of QML?

    Quote Originally Posted by anda_skoa View Post
    The height of a row is determined by the maximum height of all items in that row.
    Similarily, the width of a column is determined by the maximum wdith of all items in that column.
    Thankful for the information.

Similar Threads

  1. Spacing around legend items
    By FilipeMaia in forum Qwt
    Replies: 5
    Last Post: 13th August 2015, 09:15
  2. Replies: 5
    Last Post: 24th December 2014, 11:11
  3. How to clear the GridLayout
    By rahulgogoi in forum Qt Programming
    Replies: 7
    Last Post: 13th May 2011, 06:22
  4. QMdiArea with Gridlayout
    By ericV in forum Qt Programming
    Replies: 0
    Last Post: 14th September 2009, 11:26
  5. does gridlayout really lay out?
    By illuzioner in forum Newbie
    Replies: 2
    Last Post: 26th February 2006, 00:57

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.