Results 1 to 2 of 2

Thread: Layout without margin??

  1. #1
    Join Date
    Aug 2008
    Location
    Prague
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Layout without margin??

    Hi,

    when I wrote following simple code:

    Qt Code:
    1. QPushButton button("Button");
    2. button.show();
    To copy to clipboard, switch view to plain text mode 

    it creates me window with button without any margins around.

    But when I want to create window with two buttons, so I wrote following code:

    Qt Code:
    1. QWidget mainwindow;
    2. QHBoxLayout layout;
    3. QPushButton button1("Button A");
    4. QPushButton button2("Button B");
    5. layout.addWidget(&button1);
    6. layout.addWidget(&button2);
    7. mainwindow.setLayout(&layout);
    8. mainwindow.show();
    To copy to clipboard, switch view to plain text mode 

    But it creates me margin around both buttons and I really dont want it at all.
    Last edited by jpn; 2nd August 2008 at 09:54. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Layout without margin??

    Qt Code:
    1. layout.setMargin(0); // margin of the layout
    2. layout.setSpacing(0); // spacing between items
    To copy to clipboard, switch view to plain text mode 
    If you're using Qt 4.3 or later, you may also use:
    Qt Code:
    1. layout.setContentsMargins(left, top, right, bottom);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. Replies: 2
    Last Post: 9th July 2008, 22:28
  3. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 17:11
  4. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 22:54
  5. "dynamic" layout
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2006, 07: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.