提交 fd44d199 编写于 作者: 之一Yo's avatar 之一Yo

fixes #246

上级 9707786e
...@@ -64,20 +64,14 @@ class ListBase: ...@@ -64,20 +64,14 @@ class ListBase:
def keyPressEvent(self, e): def keyPressEvent(self, e):
QListView.keyPressEvent(self, e) QListView.keyPressEvent(self, e)
self._updateSelectedRows() self.updateSelectedRows()
def mousePressEvent(self, e):
if e.button() == Qt.LeftButton:
QListView.mousePressEvent(self, e)
else:
self._setPressedRow(self.indexAt(e.pos()).row())
def mouseReleaseEvent(self, e): def mouseReleaseEvent(self, e):
QListView.mouseReleaseEvent(self, e) QListView.mouseReleaseEvent(self, e)
row = self.indexAt(e.pos()).row() row = self.indexAt(e.pos()).row()
if row >= 0 and e.button() != Qt.RightButton: if row >= 0 and e.button() != Qt.RightButton:
self._updateSelectedRows() self.updateSelectedRows()
else: else:
self._setPressedRow(-1) self._setPressedRow(-1)
...@@ -85,19 +79,15 @@ class ListBase: ...@@ -85,19 +79,15 @@ class ListBase:
self.delegate = delegate self.delegate = delegate
super().setItemDelegate(delegate) super().setItemDelegate(delegate)
def setSelection(self, rect, command):
QListView.setSelection(self, rect, command)
self._updateSelectedRows()
def clearSelection(self): def clearSelection(self):
QListView.clearSelection(self) QListView.clearSelection(self)
self._updateSelectedRows() self.updateSelectedRows()
def setCurrentIndex(self, index: QModelIndex): def setCurrentIndex(self, index: QModelIndex):
QListView.setCurrentIndex(self, index) QListView.setCurrentIndex(self, index)
self._updateSelectedRows() self.updateSelectedRows()
def _updateSelectedRows(self): def updateSelectedRows(self):
self._setSelectedRows(self.selectedIndexes()) self._setSelectedRows(self.selectedIndexes())
...@@ -116,7 +106,7 @@ class ListWidget(ListBase, QListWidget): ...@@ -116,7 +106,7 @@ class ListWidget(ListBase, QListWidget):
else: else:
super().setCurrentRow(row, command) super().setCurrentRow(row, command)
self._updateSelectedRows() self.updateSelectedRows()
class ListView(ListBase, QListView): class ListView(ListBase, QListView):
......
...@@ -318,7 +318,7 @@ class ScrollBar(QWidget): ...@@ -318,7 +318,7 @@ class ScrollBar(QWidget):
dv = e.pos().x() - self._pressedPos.x() dv = e.pos().x() - self._pressedPos.x()
# don't use `self.setValue()`, because it could be reimplemented # 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) ScrollBar.setValue(self, self.value() + dv)
self._pressedPos = e.pos() self._pressedPos = e.pos()
......
...@@ -184,20 +184,14 @@ class TableBase: ...@@ -184,20 +184,14 @@ class TableBase:
def keyPressEvent(self, e: QKeyEvent): def keyPressEvent(self, e: QKeyEvent):
QTableView.keyPressEvent(self, e) QTableView.keyPressEvent(self, e)
self._updateSelectedRows() self.updateSelectedRows()
def mousePressEvent(self, e: QKeyEvent):
if e.button() == Qt.LeftButton:
QTableView.mousePressEvent(self, e)
else:
self._setPressedRow(self.indexAt(e.pos()).row())
def mouseReleaseEvent(self, e): def mouseReleaseEvent(self, e):
QTableView.mouseReleaseEvent(self, e) QTableView.mouseReleaseEvent(self, e)
row = self.indexAt(e.pos()).row() row = self.indexAt(e.pos()).row()
if row >= 0 and e.button() != Qt.RightButton: if row >= 0 and e.button() != Qt.RightButton:
self._updateSelectedRows() self.updateSelectedRows()
else: else:
self._setPressedRow(-1) self._setPressedRow(-1)
...@@ -207,25 +201,21 @@ class TableBase: ...@@ -207,25 +201,21 @@ class TableBase:
def selectAll(self): def selectAll(self):
QTableView.selectAll(self) QTableView.selectAll(self)
self._updateSelectedRows() self.updateSelectedRows()
def selectRow(self, row: int): def selectRow(self, row: int):
QTableView.selectRow(self, row) QTableView.selectRow(self, row)
self._updateSelectedRows() self.updateSelectedRows()
def setSelection(self, rect, command):
QTableView.setSelection(self, rect, command)
self._updateSelectedRows()
def clearSelection(self): def clearSelection(self):
QTableView.clearSelection(self) QTableView.clearSelection(self)
self._updateSelectedRows() self.updateSelectedRows()
def setCurrentIndex(self, index: QModelIndex): def setCurrentIndex(self, index: QModelIndex):
QTableView.setCurrentIndex(self, index) QTableView.setCurrentIndex(self, index)
self._updateSelectedRows() self.updateSelectedRows()
def _updateSelectedRows(self): def updateSelectedRows(self):
self._setSelectedRows(self.selectedIndexes()) self._setSelectedRows(self.selectedIndexes())
...@@ -244,7 +234,7 @@ class TableWidget(TableBase, QTableWidget): ...@@ -244,7 +234,7 @@ class TableWidget(TableBase, QTableWidget):
else: else:
super().setCurrentItem(item, command) super().setCurrentItem(item, command)
self._updateSelectedRows() self.updateSelectedRows()
class TableView(TableBase, QTableView): class TableView(TableBase, QTableView):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册