Results 1 to 4 of 4

Thread: How do I control padding/margin on the QMainWindow central widget ?

  1. #1
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How do I control padding/margin on the QMainWindow central widget ?

    I cannot figure out how to remove the padding and/or margin on the QMainWindow central widget. In fact, it is not the widget itself, it's really the QMainWindow central area. Whatever I pass to setCentralWidget( whatever ), it will always put a padding around it, such as illustrated in the attached pic.

    In this example, I have simply changed the background color in the Qt 4.5.0 demo "mainwindow". It illustrates perfectly what I'm talking about : the widget passed to setCentralWidget has a dark grey bg, and the dock separators have a blue bg. See the gap between the main grey area (widget background, no padding, no margin, no spacing) and the separator ?



    What I want is to remove all but the bottom docks, and put a banner right at the top of the central widget. The banner needs to expand all the way to the right/left/top of the window, floating right below the toolbar.

    Any assistance / guidance would be greatly appreciated. This is a work project that is due in a few days and must be presented to the public as a demo app

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How do I control padding/margin on the QMainWindow central widget ?

    Hi, get the layout via QWidget::layout() and use:
    Qt Code:
    1. layout()->setContentsMargin(0,0,0,0);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I control padding/margin on the QMainWindow central widget ?

    Ooooh I see !

    Thank you very much, this is exactly what I needed

    I was relying almost entirely on stylesheets to control the appearance of my app; I understood that QLayout cannot be styled with css, only what goes in it -- at least this is what QAssistant documentation tells us if we read the stylesheet page (it doesn't list Q*Layout as a style-able object).

    Is this assumption wrong ? Can't I control the QLayout margins with stylesheets ?

    Other parts of the Qt doc also tells me that everything has a margin & padding set to 0 by default. I can't find this bit of doc now, but I'm sure I read it somewhere.. Maybe this applies only to objects that can be styled with stylesheets ?

    Again, thanks a lot !

  4. #4
    Join Date
    Feb 2012
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I control padding/margin on the QMainWindow central widget ?

    Edit: Forget this post. After retrying a couple of things I found the white color to be that QMainWindow's background style. Of course I had already tried that but I must have suffered a typo as it was not working before.

    I keep the original post here in case someone else is interested in the margin's color and how to change it ...


    Hi there

    I hope its ok that I hijack this thread because it already contains all information I need to supply with my questions.

    I'm trying to CSS my docking widgets but there seems to be one property I cannot get my hands on

    My QDockWidget derived class uses a CSS margin to allow for some space between the docked widgets. Pretty much the same as the margin of the central widget in the image from the first post of this thread. So I have this white border around all of my docked widgets.

    The border ist indeed what I want to have but how can I change the color of the margin.

    As far as I understand the margin lets the background shine through. That's perfectly ok but who's background color is this damn white? Is there a way to change the QMainWindow backgriund color? Or is this the background color of the internal dock area (I'm using Qt 4.8 so there is no explicit QDockArea).

    You can easily reproduce this by taking the sample shown above (official Qt sample "Main Window") and set a margin for the QDockWidget. Then try to change the color that shine through the margin.

    Btw. the same applies for the toolbars I add to my QMainWindow. If they have a margin as well (which they should also have in my case) the also suffer from this ugly white background. If the overall style of the application is dark gray then this white does not look pretty fancy.

    Or is there any other way to have an offset between my docked widgets? I also need the border feature as well so I cannot just fake the desired background color on the margins by abusing the background and padding styles.

    Thanks for any input you can provide
    Last edited by mycute; 19th February 2012 at 11:49.

  5. The following user says thank you to mycute for this useful post:

    XRI-Vision (18th November 2014)

Similar Threads

  1. Replies: 2
    Last Post: 23rd March 2009, 17:26
  2. Replies: 2
    Last Post: 7th June 2008, 13:12
  3. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 13:00
  4. paint central widget of a QMainWindow???
    By Shuchi Agrawal in forum Newbie
    Replies: 3
    Last Post: 17th January 2007, 08:02
  5. Central Widget of QMainWindow
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2006, 18:32

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.