python - Qt - VBoxLayout 中 addWidget 的默认对齐方式

标签 python qt layout alignment

我在 QVBoxlayout 的 addWidget(widget,stretch,alignment) 方法中遇到 Alignment-Parameter 问题。

我正在将 QTableview 添加到我的布局中:

没有对齐参数,一切正常 - 我的表格 View 填充了布局中的整个空间。

现在,我想知道使用的默认对齐方式是什么,以便我可以将其添加到我的方法调用中。文档说,如果没有对齐参数,默认对齐参数为零。但是当我用“0”作为对齐参数调用 addWidget 时,pycharm 提示类型错误,int 而不是 Qt::Alignment...

最佳答案

开源软件的好处是您可以 take a look at the source ,代码为:

void addWidget(QWidget *, int stretch = 0, Qt::Alignment alignment = Qt::Alignment());

因此,使用相当于 Qt::Alignment() 作为最后一个参数来调用 addWidget 方法:

yourLayout.addWidget(yourWidget, 0, Qt.Alignment())  # Python
yourLayout->addWidget(yourWidget, 0, {});           // C++

关于python - Qt - VBoxLayout 中 addWidget 的默认对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52835986/

相关文章:

c++ - 有没有办法有效地更新 QML 中的 CAN 数据?

android - 如何修复布局?

rigraph 绘图布局错误 : incorrect number of subscripts on matrix

python - 在 python 中对两个 { } 使用 re.split()

python - PySpark 中 pandas_udf 的隐式模式?

Python pandas : Assign label based on sorted values per row, 不包括 NaN

linux - 如何提供Qt安装路径进行配置?

c++ - QT - 在 pro 中指定 DLL 路径。文件

python - 使用乘法生成列表是否会产生引用

java - 在没有 null 布局的 Swing 中绕过组件的布局