Widget Margin vs layout margin - qt

There is SetContentsMargin both in QWidget and layout. So is that 2 margins getting added or both are operating for the same margin. Take an example where a layout is set to the widget and the margins are set to both the widget and the layout, Is there a standard approach by Qt? And does all the in-built layout of Qt follow that? What is the original idea behind all this?

On the widget the margins are an area within the widget.
So if you have a widget with a size of 100 x 50 and margins of (5,6,5,6), then you will have a contentsRect() of QRect(5,6 90x38).
The widget can draw in its margins and as far as QLayout is concerned these margins are counted as in the widget. These margins are used to inform other widgets and subclasses of where is the "core" of the widget. This can be useful to tell subclasses where they are allowed to draw.
The margins for layouts are the same. They represent an area within the layout. If you have a layout with a left margin of 10 px, the first widget will render 10 px away from the border of the layout. If this widget has a left margin of 5 px, then the meaningful content of the widget will start 15 px away from the layout border. However, as I said before, the part for 10 px to 15 px is within the widget and the widget can draw in this space.
In layouts you also have spacing, as for the margins, it adds up to the widgets margins.
Additional info
If you place a layout inside a widget, the layout will only occupy the content rectangle (contentsRect()). Then the layout will have its own margin, counted inside the layout.
To conclude, the total visible margin is the margin of the parent widget + the margin of the layout + the margin of the child widget.

Related

Disable widget stretching in QScrollArea layout

I am trying to disable the stretching of widgets in my QScrollArea's vertical layout.
I would like to have a scroll area which resizes it's contents horizontally to fit the scroll area's width (so that the whole widget is visible), but has a scrollbar vertically if needed.
I only managed to achieve this by setting my widgets width so that it fits without a horizontal scrollbar getting added.

How to center a responsive page layout?

I'm trying to use a CSS grid from this page, but I can't seem to figure out how the outside margins of the layout is done.
How do you define the content such that it scales responsively up to a certain width, then becomes a fixed-width, centered layout when the window is larger than that size?
http://www.responsivegridsystem.com/

Can we set different alignments for widgets in QLayout?

I have many widgets in a horizontal layout. I have set alignment to vertical center and hence all the widgets are proportionately placed and the content margins are set to (0, 0, 0, 0).
I want to add one more widget which is aligned to the top and not the center.
Is there a way to add widgets with different alignment in the same layout?
One solution: To add this last widget to a vertical layout and align it to top and add that vertical layout to the horizontal layout. But this adds one more layout which i am thinking can be avoided.

gwt ScrollPanel in TabPanel: no vertical scrollbar

EDIT
I have fixed the whitespace behaviour by resizing components within the VerticalPanel, that seem to have had an effect on the panel's dimension somehow missed by the console. I don't quite understand how.
However, I am still stuck with none of my panels showing vertical scroll bars.
In a GWT project, I have the following structure:
Page
DockLayoutPanel
North (header)
Center (body)
South (footer)
/DockLayoutPanel
Body
SplitLayoutPanel$1
West
SplitLayoutPanel$2
North
Center
TabPanel
ScrollPanel
VerticalPanel
-Several widgets-
/VerticalPanel
/ScrollPanel
/TabPanel
/Center
/SplitLayoutPanel$2
/West
Center
/SplitLayoutPanel$1
My problems are with the ScrollPanel in the TabPanel, which in itself contains a VerticalPanel containing several widgets. This is true for each Tab in the TabPanel.
My problem is that, while the width's for all containers in SplitLayoutPanel$2's center have 100% width, the ScrollPanel contains a horizontal scrollbar with a considerable white area next to it's VerticalPanel, while they are in absolute metrics the same size.
Illustrating the situation
This is the TabPanel, with ScrollPanel, and VerticalPanel. Notice how the horizontal scrollbar exists, while the TabPanel, ScrollPanel and VerticalPanel have the same width. Scrolling to the right yields a white area.
The ScrollPanel and VerticalPanel all sport an absolute width of 598px. The West component of the DockLayoutPanel has a size of 600, so that matches. Also notice how bringing up the developer console has made the scrollbar disappear. In fact, the entire panel has disappeared behind it, and no vertical scrollbar pops up.
When scrolling the bar to the right, the VerticalPanel gets partially placed off screen, and the ScrollPanel shows this whitespace. Obviously, I don't want the whitespace to be there, so there won't be need for a scrollbar at all. All panels in this situation still have the same width: 598px. Resizing the SplitLayoutPanel, using the border to the right, increases these values (obviously), but the panels do still share equal width and the whitespace remains the same size, while I'd expect it to get wider too.
The second tab contains a load of text, which continues off the screen, but no scrollbars appear.
Problem conclusion
No vertical scrollbars
A horizontal scrollbar with some magically summoned whitespace
Compontents claim to have equal width
Any help is greatly appreciated.
EDIT
Have tried resizing the VerticalPanel to 90 or 80% width. The whitespace seems unaffected and it shows that 100% really covers the visible width and not more.
TabPanel (at least the one from GWT proper) resizes from the inside-out: its size varies depending on the size of the selected tab. So your ScrollPanel will never have a vertical scrollbar unless you explicitly give it a size, and your content is actually overflowing the layer of the SplitLayoutPanel you put the TabPanel in.
Layout panels, such as TabLayoutPanel, on the other hand resize from the outside-in: the SplitLayoutPanel would set the size of the TabLayoutPanel in its center region, and the TabLayoutPanel would in turn set the size of the ScrollPanel, so if the content of the ScrollPanel overflows, a vertical scrollbar appears.
First Point : Don't mix and match layout panels and non - layout panels.
Second Point : If you want proper resizing and scrollbars, always try to mention width and height in percentages.
I see that you have mentioned width to be 100%. But what about the height?
What I suggest for you is,
Change TabPanel to TabLayoutPanel
Set all the panels height throughout the heirarchy as 100%

QT: Position tabs within QTabBar block

There is a QTabBar element with a vertical size policy which is expanding. I want to make the tabs to be aligned to the bottom of the QTabBar element box, but they are always appearing from the top.
I have tried styling QTabBar and QTabBar::tab with different combinations of vertical-align: bottom, alignment: bottom;, bottom:0; but with zero luck. It seems that the only alignment that actually work is when I align horizontally.
Current results:
The tabs are separated from where the content will go. And before suggesting me to not use an expanding vertical policy. I have to do it like this, I have my reasons.
The widget alignment can be set in the containing layout, and you have to use a non-zero stretch value:
vbox->addWidget(tabBar, 1, Qt::AlignBottom);
vbox->addWidget(otherWidget, 1);
The tab will be correctly aligned, with empty space above it, but that space won't be a part of the QTabBar (the expanding policy will be ignored).
If you need to put something in the space above the QTabBar, you could insert it at the bottom of another intermediary QWidget and insert that widget into the layout instead of the QTabBar.

Resources