Why does PyQt's pyuic ignore default margins?
<p>In Qt Designer I can see <code>verticalLayout</code> has a default margin (13px), but pyuic5 always gives me <code>self.verticalLayout.setContentsMargins(0, 0, 0, 0)</code>. In <code>uiparser.py:443</code> I found this comment:</p>

<blockquote>
  <p>A layout widget should, by default, have no margins.</p>
</blockquote>

<p>and it sets the margins to <code>(0,0,0,0)</code>. Another comment also says:</p>

<blockquote>
  <p>A plain QWidget is a layout widget unless it's parent is a
   QMainWindow.  Note that the corresponding uic test is a little more
   complicated as it involves features not supported by pyuic.</p>
</blockquote>

<p>What does this mean? I'm using PyQt-5.7, and here is my ui file:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;ui version="4.0"&gt;
 &lt;class&gt;configDialog&lt;/class&gt;
 &lt;widget class="QDialog" name="configDialog"&gt;
  &lt;property name="geometry"&gt;
   &lt;rect&gt;
    &lt;x&gt;0&lt;/x&gt;
    &lt;y&gt;0&lt;/y&gt;
    &lt;width&gt;566&lt;/width&gt;
    &lt;height&gt;552&lt;/height&gt;
   &lt;/rect&gt;
  &lt;/property&gt;
  &lt;layout class="QHBoxLayout" name="horizontalLayout"&gt;
   &lt;item&gt;
    &lt;widget class="QTabWidget" name="tabWidget"&gt;
     &lt;property name="currentIndex"&gt;
      &lt;number&gt;0&lt;/number&gt;
     &lt;/property&gt;
     &lt;widget class="QWidget" name="general"&gt;
      &lt;attribute name="title"&gt;
       &lt;string&gt;General&lt;/string&gt;
      &lt;/attribute&gt;
      &lt;layout class="QVBoxLayout" name="verticalLayout"&gt;
       &lt;item&gt;
        &lt;widget class="QPushButton" name="pushButton"&gt;
         &lt;property name="text"&gt;
          &lt;string&gt;PushButton&lt;/string&gt;
         &lt;/property&gt;
        &lt;/widget&gt;
       &lt;/item&gt;
      &lt;/layout&gt;
     &lt;/widget&gt;
    &lt;/widget&gt;
   &lt;/item&gt;
  &lt;/layout&gt;
 &lt;/widget&gt;
 &lt;resources/&gt;
 &lt;connections/&gt;
&lt;/ui&gt;
</code></pre>

<p>There is a <a href="http://riverbankcomputing.com/pipermail/pyqt/2015-December/036659.html" rel="nofollow">PyQt mailing list thread</a> on this, which seems to have resulted in the default margins being forced to zero for certain widgets. I don't know whether the behaviour of the C++ uic tool has changed since then, but in Qt-5.7 it certainly doesn't behave the same way as pyuic does.</p>

<p>This can be checked in Qt Designer by selecting View -> View code. When the margins are all set to their default values, the C++ uic tool does not generate a <code>setContentsMargins</code> line at all. And if <strong>one</strong> margin is set, it will set the other values to minus one. When a margin is not set, or set to minus one, the layout will use whatever value is specified by the current style.</p>

<p>In contrast, pyuic always explicitly resets to zero any margin which is not set, or set to minus one - which effectively overrides the current style. It's hard to see how this can be the correct behaviour - so maybe it's a regression?</p>

python qt layout pyqt qt-designer