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

fixes #246

上级 9707786e
......@@ -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):
......
......@@ -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()
......
......@@ -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):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册