PDA

View Full Version : How do I control padding/margin on the QMainWindow central widget ?



magnosis
29th April 2009, 16:14
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 ?

http://www.magnosis.com/mainwindow.jpg

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 :eek:

Lykurg
29th April 2009, 16:30
Hi, get the layout via QWidget::layout() and use:
layout()->setContentsMargin(0,0,0,0);

magnosis
29th April 2009, 17:43
Ooooh I see !

Thank you very much, this is exactly what I needed :cool:

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 !

mycute
19th February 2012, 12:40
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:confused: