Results 1 to 2 of 2

Thread: Alignment in nested layouts

  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Alignment in nested layouts

    When a RowLayout is nested inside a ColumnLayout, alignment for items in the RowLayout doesn't work:

    Знімок екрана 2017-03-02 17.08.57.jpg

    Qt Code:
    1. import QtQuick 2.7
    2. import QtQuick.Controls 2.0
    3. import QtQuick.Layouts 1.0
    4.  
    5. ApplicationWindow {
    6. visible: true
    7. width: 640
    8. height: 480
    9. title: qsTr("Hello World")
    10.  
    11. ColumnLayout
    12. {
    13. anchors.fill: parent
    14. anchors.margins: 20
    15.  
    16. Label { text: qsTr("Alignment works properly"); color: "green"; Layout.alignment: Qt.AlignRight }
    17.  
    18. RowLayout
    19. {
    20. //Layout.alignment: Qt.AlignJustify
    21. //Layout.fillWidth: true
    22. Label { text: "Left"; color: "blue"; Layout.alignment: Qt.AlignLeft }
    23. Label { text: "Right (doesn't work)"; color: "red"; Layout.alignment: Qt.AlignRight }
    24. //Rectangle { color: "red"; height: 50; Layout.fillWidth: true }
    25. //Rectangle { color: "red"; height: 50; width: 50; Layout.alignment: Qt.AlignRight }
    26. } // RowLayout
    27. } // ColumnLayout
    28.  
    29. footer: RowLayout { Label { text: "Here it works too"; Layout.alignment: Qt.AlignRight } }
    30. }
    To copy to clipboard, switch view to plain text mode 

    Is there any way to make it work?
    Magicians do not exist

  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: Alignment in nested layouts

    You are trying to do horizontal alignment in a horizontal layout, i.e. in the direction that the layout controls.

    You can either

    * add a "spacer" item between the two labels that takes all the available space, pushing the two labels to the edges
    * use an Item instead of the RowLayout and just anchor the two labels to each of its sides

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 8th November 2014, 12:47
  2. Nested Layouts and sizePolicy
    By pagapov in forum Newbie
    Replies: 13
    Last Post: 24th October 2010, 09:29
  3. Layouts
    By csvivek in forum Qt Tools
    Replies: 3
    Last Post: 7th May 2008, 07:22
  4. Layouts
    By Dumbledore in forum Qt Tools
    Replies: 1
    Last Post: 14th October 2007, 01:01
  5. Layouts - Name cant be set
    By manivannan_1984 in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2006, 18:38

Tags for this Thread

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.