Results 1 to 4 of 4

Thread: setAlignment in Layout

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    43
    Thanked 3 Times in 3 Posts

    Default Re: setAlignment in Layout

    The snippet below illustrates the problem. I have a QVBoxLayout for which I've set the Alignment to AlignCenter. I've then added two labels to it. The first label is properly centered, but only because it is within it's own HBoxLayout, for which AlignCenter is set.

    Qt Code:
    1. // Vertical Box Layout
    2. QVBoxLayout *wlogVB_cLL = new QVBoxLayout;
    3. wlogVB_cLL->setAlignment(Qt::AlignCenter);
    4.  
    5. // FIRST item
    6. QHBoxLayout *wlogHB_dLL = new QHBoxLayout;
    7. wlogHB_dLL->setAlignment(Qt::AlignCenter);
    8. QLabel *laWellLL = new QLabel;
    9. laWellLL->setText("First");
    10. wlogHB_dLL->addWidget(laWellLL);
    11. wlogVB_cLL->addLayout(wlogHB_dLL);
    12.  
    13. // SECOND item
    14. QLabel *laWellLL2 = new QLabel;
    15. laWellLL2->setText("Second");
    16. wlogVB_cLL->addWidget(laWellLL2);
    17.  
    18. // Additional items, some of which are in HBoxLayouts
    To copy to clipboard, switch view to plain text mode 

    The second label, however: it is Aligned to the left... despite the fact that I set the *vertical* box layout to be AlignCenter. The only way I can get it to align center: put it in an HBoxLayout, just like "first".

    Perhaps this is the way it's supposed to work... though I don't understand why.

    My guess (I can't test it at the moment): if the VBoxLayout *only* had widgets, the setAlignment(Qt::AlignCenter) would work. But because it contains a mix of widgets and layouts, it doesn't work... and therefore *all* of the widgets must be contained in an HBoxLayout, each of which has alignment set to Center.
    Last edited by vonCZ; 29th April 2009 at 08:32.

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 21:21
  2. Qt like Layout Manager available for .NET platform
    By vkhaitan in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 14:36
  3. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 18:11
  4. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 23:54
  5. "dynamic" layout
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2006, 08:16

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
  •  
Qt is a trademark of The Qt Company.