I use PySide instead, therefore in my program, instead
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:
self.right = QVBoxLayout()
self.right.setMargin(10)
AttributeError: 'PySide.QtGui.QVBoxLayout' object has no attribute '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. That means I can call it by importing QLayout from Pyside.QtGui but that doesn't work. The cmd say:
NotImplementedError: 'QLayout' represents a C++ abstract class and cannot be instantiated
Could you please show me how to use setMargin() by an alternative way in my case?
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:
self.right = QVBoxLayout()
self.right.setContentsMargins(10, 10, 10, 10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With