When I use QGridLayout, the first child widget was always start with the coordinate (x,y) = (1,1)
-
How to set the coordinate (x,y) to (0,0)?
For example, I have a QGridLayout 'layout' contained in a QWidget 'mainWidget' with geometry(X,Y,Width, Height) = (0, 0, 1280,1024)
and the 'layout' contains only one single element QWidget 'child', the 'child' always comes with the geometry(1,1,1280,1024)
and that will force the QGridLayout's size changed to be (1282, 1026).
How to fix of this. -
Hi, welcome to Qt forums.
bq. void QLayout::setContentsMargins(int left, int top, int right, int bottom)
Sets the left, top, right, and bottom margins to use around the layout.
By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions. -
ping it, i wanna to know if that's a bug.
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWidget</class>
<widget class="QWidget" name="MainWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1280</width>
<height>1024</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>1280</width>
<height>1024</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1280</width>
<height>1024</height>
</size>
</property>
<property name="windowTitle">
<string>MainWidget</string>
</property>
<property name="styleSheet">
<string notr="true">QFrame#titleBar { background-color: CadetBlue }
QFrame#statusBar { background-color: CadetBlue }
QFrame#controlFrame { background-color: Gray }
QFrame#buttonArea { background-color: Purple }</string>
</property>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1282</width>
<height>1026</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QFrame" name="titleBar">
<property name="minimumSize">
<size>
<width>1280</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1280</width>
<height>21</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="MainMenu" name="menuBar">
<property name="minimumSize">
<size>
<width>1280</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1280</width>
<height>21</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QFrame" name="mainFrame">
<property name="minimumSize">
<size>
<width>1024</width>
<height>768</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1024</width>
<height>768</height>
</size>
</property>
</widget>
</item>
<item row="2" column="1" rowspan="2">
<widget class="QFrame" name="controlFrame">
<property name="minimumSize">
<size>
<width>256</width>
<height>961</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>256</width>
<height>961</height>
</size>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QFrame" name="buttonArea">
<property name="minimumSize">
<size>
<width>1024</width>
<height>193</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1024</width>
<height>193</height>
</size>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QFrame" name="statusBar">
<property name="minimumSize">
<size>
<width>1280</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1280</width>
<height>21</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>MainMenu</class>
<extends>QMenuBar</extends>
<header>MainMenu.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>The layout <layout class="QGridLayout" name="gridLayout">
forced the size of <widget class="QWidget" name="gridLayoutWidget">
to be 1282*1026 -
I'm sure that you can do it with styles setting "border: 0px;".
[quote author="lygstate" date="1373268038"]I am using the QT designer, the .ui file,
if i am not wrong, then the margins should be (0,0,0,0)
is that possible to modify the content margins in the UI?
[/quote] -
I was really confused about this:
style code
@
QFrame#titleBar { background-color: CadetBlue }
QFrame#statusBar { background-color: CadetBlue }
QFrame#controlFrame { background-color: Gray }
QFrame#buttonArea { background-color: Purple }
border: 0px;
@
The QT Creator show the following results:
!http://lygstate.github.io/images/2013-07-09/MainWidget.jpg(The main widget size)!
!http://lygstate.github.io/images/2013-07-09/layout.jpg(The layout size)!
!http://lygstate.github.io/images/2013-07-09/FirstItem.jpg(The row:0 column:0 item of the layout.)!I was confused about the X,Y value of the first child of the layout.
why it's (1,1) but (0,0)?