为什么 PyQt 的 pyuic 会忽略默认边距?

Why does PyQt's pyuic ignore default margins?

在 Qt Designer 中我可以看到 verticalLayout 有一个默认边距 (13px),但是 pyuic5 总是给我 self.verticalLayout.setContentsMargins(0, 0, 0, 0)。在 uiparser.py:443 我发现了这条评论:

A layout widget should, by default, have no margins.

并将页边距设置为 (0,0,0,0)。另一条评论也说:

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.

这是什么意思?我正在使用 PyQt-5.7,这是我的 ui 文件:

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

这里有一个 PyQt mailing list thread,这似乎导致某些小部件的默认边距被强制为零。我不知道 C++ uic 工具的行为是否从那时起发生了变化,但在 Qt-5.7 中它的行为肯定与 pyuic 的行为不同。

这可以在 Qt Designer 中通过选择查看 -> 查看代码来检查。当边距都设置为其默认值时,C++ uic 工具根本不会生成 setContentsMargins 行。如果设置了 one margin,它会将其他值设置为负一。当边距未设置或设置为负一时,布局将使用当前样式指定的任何值。

相比之下,pyuic 总是明确地将任何未设置的边距重置为零,或设置为减一 - 这有效地覆盖了当前样式。很难看出这是正确的行为 - 所以这可能是一种倒退?