简体   繁体   English

setMargin() 方法不适用于 Qt Python 中的 QVBoxLayout

[英]setMargin() method not worked for QVBoxLayout in Qt Python

I use PySide instead, therefore in my program, instead我改用 PySide,因此在我的程序中,

from PySide.QtGui import QVBoxLayout

Normally it works for importing but then when I called method .setMargin() as the tutorial : https://doc.qt.io/qtforpython/tutorials/expenses/expenses.html#right-side-layout , I got an error:通常它适用于导入,但是当我调用方法 .setMargin() 作为教程时: https://doc.qt.io/qtforpython/tutorials/expenses/expenses.html#right-side-layout ,我收到一个错误:

self.right = QVBoxLayout()
self.right.setMargin(10)

AttributeError: 'PySide.QtGui.QVBoxLayout' object has no attribute 'setMargin' AttributeError: 'PySide.QtGui.QVBoxLayout' 对象没有属性 'setMargin'

I tried to find the setMargin() in the library and it appear here: https://doc.qt.io/qtforpython/PySide2/QtWidgets/QLayout.html#PySide2.QtWidgets.PySide2.QtWidgets.QLayout.setMargin .我试图在库中找到 setMargin() ,它出现在这里: https://doc.qt.io/qtforpython/PySide2/QtWidgets/QLayout.html#PySide2.QtWidgets.PySide2.QtWidgets.QLayout.setMargin That means I can call it by importing QLayout from Pyside.QtGui but that doesn't work.这意味着我可以通过从 Pyside.QtGui 导入 QLayout 来调用它,但这不起作用。 The cmd say: cmd说:

NotImplementedError: 'QLayout' represents a C++ abstract class and cannot be instantiated NotImplementedError: 'QLayout' 代表一个 C++ 抽象类并且不能被实例化

Could you please show me how to use setMargin() by an alternative way in my case?你能告诉我如何在我的情况下通过另一种方式使用 setMargin() 吗?

setMargin() does not exist in Qt4 (PySide), it existed in initial versions of Qt5 but is currently deprecated, instead you must use the setContentsMargins() method: setMargin()在 Qt4 (PySide setMargin()中不存在,它存在于 Qt5 的初始版本中,但目前已弃用,您必须使用setContentsMargins()方法:

self.right = QVBoxLayout()
self.right.setContentsMargins(10, 10, 10, 10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM