PyQt6: QBoxLayout.setAlignment(Qt.AlignmentFlag) raises TypeError
Phil Thompson
phil at riverbankcomputing.com
Mon Apr 26 10:40:17 BST 2021
On 26/04/2021 10:03, Ales Erjavec wrote:
> 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])
> ```
Fixed in the next snapshot.
Thanks,
Phil
More information about the PyQt
mailing list