From bfdeb4089872a433749a95df0b366c83b0091de4 Mon Sep 17 00:00:00 2001 From: TilmanK Date: Fri, 3 Jul 2020 08:57:48 +0200 Subject: [PATCH 1/3] Made parameter model of QAbstractItemView.setModel optional When passing None to setModel the model will be removed from the view. Qt handles this internal by setting a dummy model when a null pointer is passed: https://stackoverflow.com/questions/46630185/qt-remove-model-from-view --- PyQt5-stubs/QtWidgets.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyQt5-stubs/QtWidgets.pyi b/PyQt5-stubs/QtWidgets.pyi index 4dc8c64e..1de2db7c 100644 --- a/PyQt5-stubs/QtWidgets.pyi +++ b/PyQt5-stubs/QtWidgets.pyi @@ -786,7 +786,7 @@ class QAbstractItemView(QAbstractScrollArea): def selectionModel(self) -> QtCore.QItemSelectionModel: ... def setSelectionModel(self, selectionModel: QtCore.QItemSelectionModel) -> None: ... def model(self) -> QtCore.QAbstractItemModel: ... - def setModel(self, model: QtCore.QAbstractItemModel) -> None: ... + def setModel(self, model: typing.Optional[QtCore.QAbstractItemModel]) -> None: ... class QAbstractSlider(QWidget): From adfa1531a3096fc21e81643723c81545de65e2e5 Mon Sep 17 00:00:00 2001 From: TilmanK Date: Sat, 4 Jul 2020 08:35:54 +0200 Subject: [PATCH 2/3] Fixed annotation for inherited setModel methods too. --- PyQt5-stubs/QtWidgets.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PyQt5-stubs/QtWidgets.pyi b/PyQt5-stubs/QtWidgets.pyi index 1de2db7c..327032ee 100644 --- a/PyQt5-stubs/QtWidgets.pyi +++ b/PyQt5-stubs/QtWidgets.pyi @@ -1591,7 +1591,7 @@ class QColumnView(QAbstractItemView): def selectAll(self) -> None: ... def setRootIndex(self, index: QtCore.QModelIndex) -> None: ... def setSelectionModel(self, selectionModel: QtCore.QItemSelectionModel) -> None: ... - def setModel(self, model: QtCore.QAbstractItemModel) -> None: ... + def setModel(self, model: typing.Optional[QtCore.QAbstractItemModel]) -> None: ... def visualRect(self, index: QtCore.QModelIndex) -> QtCore.QRect: ... def sizeHint(self) -> QtCore.QSize: ... def scrollTo(self, index: QtCore.QModelIndex, hint: QAbstractItemView.ScrollHint = ...) -> None: ... @@ -5421,7 +5421,7 @@ class QHeaderView(QAbstractItemView): def length(self) -> int: ... def offset(self) -> int: ... def orientation(self) -> QtCore.Qt.Orientation: ... - def setModel(self, model: QtCore.QAbstractItemModel) -> None: ... + def setModel(self, model: typing.Optional[QtCore.QAbstractItemModel]) -> None: ... class QInputDialog(QDialog): @@ -8586,7 +8586,7 @@ class QTableView(QAbstractItemView): def horizontalHeader(self) -> QHeaderView: ... def setSelectionModel(self, selectionModel: QtCore.QItemSelectionModel) -> None: ... def setRootIndex(self, index: QtCore.QModelIndex) -> None: ... - def setModel(self, model: QtCore.QAbstractItemModel) -> None: ... + def setModel(self, model: typing.Optional[QtCore.QAbstractItemModel]) -> None: ... class QTableWidgetSelectionRange(sip.simplewrapper): @@ -9326,7 +9326,7 @@ class QTreeView(QAbstractItemView): def header(self) -> QHeaderView: ... def setSelectionModel(self, selectionModel: QtCore.QItemSelectionModel) -> None: ... def setRootIndex(self, index: QtCore.QModelIndex) -> None: ... - def setModel(self, model: QtCore.QAbstractItemModel) -> None: ... + def setModel(self, model: typing.Optional[QtCore.QAbstractItemModel]) -> None: ... class QTreeWidgetItem(sip.wrapper): From cca7a2016d084baa3d690f0b3fee3d9343128559 Mon Sep 17 00:00:00 2001 From: TilmanK Date: Sat, 4 Jul 2020 08:37:50 +0200 Subject: [PATCH 3/3] Updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c134c64b..684009b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed * [#46](https://github.com/stlehmann/PyQt5-stubs/pull/46) fixes QCoreApplication and QObject signals * [#48](https://github.com/stlehmann/PyQt5-stubs/pull/48) fixes some signals for QClipBoard, QWindows, QQuickView and QQml{Application,}Engine +* [#49](https://github.com/stlehmann/PyQt5-stubs/pull/49) fixes QAbstractItemView.setModel to accept None ### Removed