PyQt6: QBoxLayout.setAlignment(Qt.AlignmentFlag) raises TypeError
Ales Erjavec
ales.erjavec324 at gmail.com
Mon Apr 26 10:03:57 BST 2021
Hi,
Trying to set an alignment on a QBoxLayout raises a TypeError:
```
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication, QWidget, QHBoxLayout
app = QApplication([])
lay = QHBoxLayout()
lay.setAlignment(Qt.AlignmentFlag.AlignLeft) # << error
```
The error:
```
TypeError: arguments did not match any overloaded call:
setAlignment(self, QWidget, Qt.AlignmentFlag): argument 1 has
unexpected type 'AlignmentFlag'
setAlignment(self, QLayout, Qt.AlignmentFlag): argument 1 has
unexpected type 'AlignmentFlag'
```
The two listed overloads are from QLayout implementation but the
intended call is for
the base QLayoutItem.setAlignment.
In PyQt5 this worked as evident by the QHBoxLayout.setAlignment docstring:
```
setAlignment(self, QWidget, Union[Qt.Alignment, Qt.AlignmentFlag]) -> bool
setAlignment(self, QLayout, Union[Qt.Alignment, Qt.AlignmentFlag]) -> bool
setAlignment(self, Union[Qt.Alignment, Qt.AlignmentFlag])
```
Best wishes
Aleš Erjavec
More information about the PyQt
mailing list