本文整理汇总了Python中PyQt5.QtWidgets.QTableView.setHorizontalScrollMode方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setHorizontalScrollMode方法的具体用法?Python QTableView.setHorizontalScrollMode怎么用?Python QTableView.setHorizontalScrollMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.setHorizontalScrollMode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RelationDialog
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setHorizontalScrollMode [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)