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

修复表格视图无法使用键盘控制选中的问题

上级 03ad7b99
......@@ -2,7 +2,7 @@
from typing import List
from PyQt5.QtCore import Qt, QMargins, QModelIndex
from PyQt5.QtGui import QPainter, QColor
from PyQt5.QtGui import QPainter, QColor, QKeyEvent
from PyQt5.QtWidgets import (QStyledItemDelegate, QApplication, QStyleOptionViewItem,
QTableView, QTableWidget, QWidget)
......@@ -178,6 +178,16 @@ class TableBase:
e.setAccepted(True)
def keyPressEvent(self, e: QKeyEvent):
QTableView.keyPressEvent(self, e)
self.setSelectedRows(self.selectedIndexes())
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):
row = self.indexAt(e.pos()).row()
if row >= 0 and e.button() != Qt.RightButton:
......@@ -195,10 +205,8 @@ class TableWidget(QTableWidget, TableBase):
super().__init__(parent)
class TableView(QTableView, TableBase):
""" Table view """
def __init__(self, parent=None):
super().__init__(parent)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册