gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 17:24:30 24 4
gpt4 key购买 nike

在 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 边距,它会将其他值设置为负一。当边距未设置或设置为负一时,布局将使用当前样式指定的任何值。

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

关于python - 为什么 PyQt 的 pyuic 会忽略默认边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39910217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com