From fd44d199db4d2cb9145841113054616a60136603 Mon Sep 17 00:00:00 2001 From: zhiyiYo <1319158137@qq.com> Date: Thu, 1 Jun 2023 17:47:43 +0800 Subject: [PATCH] fixes #246 --- .../components/widgets/list_view.py | 22 +++++----------- .../components/widgets/scroll_bar.py | 2 +- .../components/widgets/table_view.py | 26 ++++++------------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/qfluentwidgets/components/widgets/list_view.py b/qfluentwidgets/components/widgets/list_view.py index 57298c6..9538639 100644 --- a/qfluentwidgets/components/widgets/list_view.py +++ b/qfluentwidgets/components/widgets/list_view.py @@ -64,20 +64,14 @@ class ListBase: def keyPressEvent(self, e): QListView.keyPressEvent(self, e) - self._updateSelectedRows() - - def mousePressEvent(self, e): - if e.button() == Qt.LeftButton: - QListView.mousePressEvent(self, e) - else: - self._setPressedRow(self.indexAt(e.pos()).row()) + self.updateSelectedRows() def mouseReleaseEvent(self, e): QListView.mouseReleaseEvent(self, e) row = self.indexAt(e.pos()).row() if row >= 0 and e.button() != Qt.RightButton: - self._updateSelectedRows() + self.updateSelectedRows() else: self._setPressedRow(-1) @@ -85,19 +79,15 @@ class ListBase: self.delegate = delegate super().setItemDelegate(delegate) - def setSelection(self, rect, command): - QListView.setSelection(self, rect, command) - self._updateSelectedRows() - def clearSelection(self): QListView.clearSelection(self) - self._updateSelectedRows() + self.updateSelectedRows() def setCurrentIndex(self, index: QModelIndex): QListView.setCurrentIndex(self, index) - self._updateSelectedRows() + self.updateSelectedRows() - def _updateSelectedRows(self): + def updateSelectedRows(self): self._setSelectedRows(self.selectedIndexes()) @@ -116,7 +106,7 @@ class ListWidget(ListBase, QListWidget): else: super().setCurrentRow(row, command) - self._updateSelectedRows() + self.updateSelectedRows() class ListView(ListBase, QListView): diff --git a/qfluentwidgets/components/widgets/scroll_bar.py b/qfluentwidgets/components/widgets/scroll_bar.py index 58f28f9..385f952 100644 --- a/qfluentwidgets/components/widgets/scroll_bar.py +++ b/qfluentwidgets/components/widgets/scroll_bar.py @@ -318,7 +318,7 @@ class ScrollBar(QWidget): dv = e.pos().x() - self._pressedPos.x() # don't use `self.setValue()`, because it could be reimplemented - dv = dv / self._slideLength() * (self.maximum() - self.minimum()) + dv = int(dv / self._slideLength() * (self.maximum() - self.minimum())) ScrollBar.setValue(self, self.value() + dv) self._pressedPos = e.pos() diff --git a/qfluentwidgets/components/widgets/table_view.py b/qfluentwidgets/components/widgets/table_view.py index 15efc56..e2d0993 100644 --- a/qfluentwidgets/components/widgets/table_view.py +++ b/qfluentwidgets/components/widgets/table_view.py @@ -184,20 +184,14 @@ class TableBase: def keyPressEvent(self, e: QKeyEvent): QTableView.keyPressEvent(self, e) - self._updateSelectedRows() - - def mousePressEvent(self, e: QKeyEvent): - if e.button() == Qt.LeftButton: - QTableView.mousePressEvent(self, e) - else: - self._setPressedRow(self.indexAt(e.pos()).row()) + self.updateSelectedRows() def mouseReleaseEvent(self, e): QTableView.mouseReleaseEvent(self, e) row = self.indexAt(e.pos()).row() if row >= 0 and e.button() != Qt.RightButton: - self._updateSelectedRows() + self.updateSelectedRows() else: self._setPressedRow(-1) @@ -207,25 +201,21 @@ class TableBase: def selectAll(self): QTableView.selectAll(self) - self._updateSelectedRows() + self.updateSelectedRows() def selectRow(self, row: int): QTableView.selectRow(self, row) - self._updateSelectedRows() - - def setSelection(self, rect, command): - QTableView.setSelection(self, rect, command) - self._updateSelectedRows() + self.updateSelectedRows() def clearSelection(self): QTableView.clearSelection(self) - self._updateSelectedRows() + self.updateSelectedRows() def setCurrentIndex(self, index: QModelIndex): QTableView.setCurrentIndex(self, index) - self._updateSelectedRows() + self.updateSelectedRows() - def _updateSelectedRows(self): + def updateSelectedRows(self): self._setSelectedRows(self.selectedIndexes()) @@ -244,7 +234,7 @@ class TableWidget(TableBase, QTableWidget): else: super().setCurrentItem(item, command) - self._updateSelectedRows() + self.updateSelectedRows() class TableView(TableBase, QTableView): -- GitLab