本文整理汇总了Python中PyQt5.QtWidgets.QTableView.resizeColumnToContents方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.resizeColumnToContents方法的具体用法?Python QTableView.resizeColumnToContents怎么用?Python QTableView.resizeColumnToContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.resizeColumnToContents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GroupWidget
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import resizeColumnToContents [as 别名]
class GroupWidget(QWidget):
_COLUMN_MAP = students.StudentColumnMap(
columns=[
students.StudentColumn.SEQUENCE_NUM,
students.StudentColumn.ID,
students.StudentColumn.NAME,
])
def __init__(self, listing, student_tabs):
super().__init__(student_tabs.tabs)
self.listing = listing
layout = QVBoxLayout()
self.setLayout(layout)
self.table = QTableView()
self.table.setMinimumWidth(500)
self.table.setMinimumHeight(300)
layout.addWidget(self.table)
self.model = StudentsTableModel(listing, GroupWidget._COLUMN_MAP, self)
self.table.setModel(self.model)
self.table.setSelectionBehavior(QTableView.SelectRows)
layout.setAlignment(self.table, Qt.AlignHCenter)
self._resize_table()
def add_students(self, student_list):
self.listing.add_students(student_list)
self.listing_updated()
def listing_updated(self):
self.model.data_reset()
self._resize_table()
def _resize_table(self):
self.table.resizeColumnToContents(0)
self.table.horizontalHeader().setStretchLastSection(True)
示例2: PreviewWidget
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import resizeColumnToContents [as 别名]
class PreviewWidget(QWidget):
def __init__(self, student_list, column_map, parent=None):
super().__init__(parent)
self.listing = students.GroupListing(None, student_list)
self.column_map = column_map
layout = QVBoxLayout()
self.setLayout(layout)
self.table = QTableView()
self.table.setMinimumWidth(600)
self.table.setMinimumHeight(300)
layout.addWidget(self.table)
self.model = StudentsTableModel(self.listing, column_map, self)
self.table.setModel(self.model)
self.table.setSelectionMode(QTableView.NoSelection)
layout.setAlignment(self.table, Qt.AlignHCenter)
self._resize_table()
def swap_names(self):
for s in self.listing.students:
s.first_name, s.last_name = s.last_name, s.first_name
self.model.data_reset()
self._resize_table()
def to_full_name(self, column):
attr_name = students.ATTR_NAME[column]
for s in self.listing.students:
s.full_name = getattr(s, attr_name)
s.first_name = ''
s.last_name = ''
self.column_map = self.column_map.to_full_name()
self.model.data_reset(column_map=self.column_map)
self._resize_table()
def remove_duplicates(self):
self.listing.remove_students([s for s in self.listing.students
if s.is_duplicate])
self.model.data_reset()
def _resize_table(self):
for i in range(len(self.column_map) - 1):
self.table.resizeColumnToContents(i)
self.table.horizontalHeader().setStretchLastSection(True)