本文整理汇总了Python中PyQt5.QtWidgets.QTableView.setVerticalScrollMode方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setVerticalScrollMode方法的具体用法?Python QTableView.setVerticalScrollMode怎么用?Python QTableView.setVerticalScrollMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.setVerticalScrollMode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RelationDialog
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setVerticalScrollMode [as 别名]
class RelationDialog(QDialog):
""" Base class for creator and edit relation """
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setWindowTitle(self.tr("Relation Editor"))
# Data
self.data = None
self.resize(700, 500)
box = QVBoxLayout(self)
# Relation name
self.relation_name = QLineEdit()
self.relation_name.setVisible(False)
box.addWidget(self.relation_name)
# Buttons
box_btns = QHBoxLayout()
add_tuple_btn = QPushButton(self.tr("Add Tuple"))
box_btns.addWidget(add_tuple_btn)
delete_tuple_btn = QPushButton(self.tr("Delete Tuple"))
box_btns.addWidget(delete_tuple_btn)
add_column_btn = QPushButton(self.tr("Add Column"))
box_btns.addWidget(add_column_btn)
delete_column_btn = QPushButton(self.tr("Delete Column"))
box_btns.addWidget(delete_column_btn)
box.addLayout(box_btns)
# Table
self.table = QTableView()
self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
self.table.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
self.table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
# Editable header
header = custom_table.Header()
self.table.setHorizontalHeader(header)
box.addWidget(self.table)
# Save and cancel button
hbox = QHBoxLayout()
hbox.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding))
save_btn = QPushButton(self.tr("Ok"))
hbox.addWidget(save_btn)
cancel_btn = QPushButton(self.tr("Cancel"))
hbox.addWidget(cancel_btn)
box.addLayout(hbox)
# Connections
save_btn.clicked.connect(self.save)
cancel_btn.clicked.connect(self.close)
add_tuple_btn.clicked.connect(self.__add_tuple)
delete_tuple_btn.clicked.connect(self.__delete_tuple)
add_column_btn.clicked.connect(self.__add_column)
delete_column_btn.clicked.connect(self.__delete_column)
def setup_table(self, rela):
raise NotImplementedError
def save(self):
raise NotImplementedError
def __add_tuple(self):
model = self.table.model()
model.insertRow(model.rowCount())
def __delete_tuple(self):
model = self.table.model()
selection = self.table.selectionModel()
if selection.hasSelection():
r = QMessageBox.question(
self,
self.tr("Confirm tuple delete"),
self.tr("Are you sure you want " "to delete the selected " "tuple(s)?"),
QMessageBox.Yes | QMessageBox.No,
)
if r == QMessageBox.Yes:
selection = selection.selection()
rows = set([index.row() for index in selection.indexes()])
rows = sorted(list(rows))
previous = -1
i = len(rows) - 1
while i >= 0:
current = rows[i]
if current != previous:
model.removeRows(current, 1)
i -= 1
def __add_column(self):
model = self.table.model()
model.insertColumn(model.columnCount())
def __delete_column(self):
model = self.table.model()
if model.columnCount() >= 2:
model.takeColumn(model.columnCount() - 1)
示例2: FreezeTableWidget
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setVerticalScrollMode [as 别名]
class FreezeTableWidget(QTableView):
def __init__(self, model):
super(FreezeTableWidget, self).__init__()
self.setModel(model)
self.frozenTableView = QTableView(self)
self.init()
self.horizontalHeader().sectionResized.connect(self.updateSectionWidth)
self.verticalHeader().sectionResized.connect(self.updateSectionHeight)
self.frozenTableView.verticalScrollBar().valueChanged.connect(
self.verticalScrollBar().setValue)
self.verticalScrollBar().valueChanged.connect(
self.frozenTableView.verticalScrollBar().setValue)
def init(self):
self.frozenTableView.setModel(self.model())
self.frozenTableView.setFocusPolicy(Qt.NoFocus)
self.frozenTableView.verticalHeader().hide()
self.frozenTableView.horizontalHeader().setSectionResizeMode(
QHeaderView.Fixed)
self.viewport().stackUnder(self.frozenTableView)
self.frozenTableView.setStyleSheet('''
QTableView { border: none;
background-color: #8EDE21;
selection-background-color: #999;
}''') # for demo purposes
self.frozenTableView.setSelectionModel(self.selectionModel())
for col in range(1, self.model().columnCount()):
self.frozenTableView.setColumnHidden(col, True)
self.frozenTableView.setColumnWidth(0, self.columnWidth(0))
self.frozenTableView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.frozenTableView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.frozenTableView.show()
self.updateFrozenTableGeometry()
self.setHorizontalScrollMode(self.ScrollPerPixel)
self.setVerticalScrollMode(self.ScrollPerPixel)
self.frozenTableView.setVerticalScrollMode(self.ScrollPerPixel)
def updateSectionWidth(self, logicalIndex, oldSize, newSize):
if self.logicalIndex == 0:
self.frozenTableView.setColumnWidth(0, newSize)
self.updateFrozenTableGeometry()
def updateSectionHeight(self, logicalIndex, oldSize, newSize):
self.frozenTableView.setRowHeight(logicalIndex, newSize)
def resizeEvent(self, event):
super(FreezeTableWidget, self).resizeEvent(event)
self.updateFrozenTableGeometry()
def moveCursor(self, cursorAction, modifiers):
current = super(FreezeTableWidget, self).moveCursor(cursorAction, modifiers)
if (cursorAction == self.MoveLeft and
self.current.column() > 0 and
self.visualRect(current).topLeft().x() <
self.frozenTableView.columnWidth(0)):
newValue = (self.horizontalScrollBar().value() +
self.visualRect(current).topLeft().x() -
self.frozenTableView.columnWidth(0))
self.horizontalScrollBar().setValue(newValue)
return current
def scrollTo(self, index, hint):
if index.column() > 0:
super(FreezeTableWidget, self).scrollTo(index, hint)
def updateFrozenTableGeometry(self):
self.frozenTableView.setGeometry(
self.verticalHeader().width() + self.frameWidth(),
self.frameWidth(), self.columnWidth(0),
self.viewport().height() + self.horizontalHeader().height())