本文整理汇总了Python中PyQt5.Qt.QTableView.setColumnWidth方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setColumnWidth方法的具体用法?Python QTableView.setColumnWidth怎么用?Python QTableView.setColumnWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QTableView
的用法示例。
在下文中一共展示了QTableView.setColumnWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AnnotatedBooksDialog
# 需要导入模块: from PyQt5.Qt import QTableView [as 别名]
# 或者: from PyQt5.Qt.QTableView import setColumnWidth [as 别名]
#.........这里部分代码省略.........
self.tv.setSelectionBehavior(self.tv.SelectRows)
# Connect signals
self.tv.doubleClicked.connect(self.getTableRowDoubleClick)
self.tv.horizontalHeader().sectionClicked.connect(self.capture_sort_column)
# Hide the vertical self.header
self.tv.verticalHeader().setVisible(False)
# Hide uuid, book_id, genre, confidence
self.tv.hideColumn(self.annotations_header.index('uuid'))
self.tv.hideColumn(self.annotations_header.index('book_id'))
self.tv.hideColumn(self.annotations_header.index('genre'))
self.tv.hideColumn(self.annotations_header.index('Confidence'))
# Set horizontal self.header props
self.tv.horizontalHeader().setStretchLastSection(True)
narrow_columns = ['Last Annotation', 'Reader App', 'Annotations']
extra_width = 10
breathing_space = 20
# Set column width to fit contents
self.tv.resizeColumnsToContents()
perfect_width = 10 + (len(narrow_columns) * extra_width)
for i in range(3, 8):
perfect_width += self.tv.columnWidth(i) + breathing_space
self.tv.setMinimumSize(perfect_width, 100)
self.perfect_width = perfect_width
# Add some width to narrow columns
for nc in narrow_columns:
cw = self.tv.columnWidth(self.annotations_header.index(nc))
self.tv.setColumnWidth(self.annotations_header.index(nc), cw + extra_width)
# Set row height
fm = QFontMetrics(self.FONT)
nrows = len(self.tabledata)
for row in xrange(nrows):
self.tv.setRowHeight(row, fm.height() + 4)
self.tv.setSortingEnabled(True)
sort_column = self.opts.prefs.get('annotated_books_dialog_sort_column',
self.annotations_header.index('Confidence'))
sort_order = self.opts.prefs.get('annotated_books_dialog_sort_order',
Qt.DescendingOrder)
self.tv.sortByColumn(sort_column, sort_order)
# ~~~~~~~~ Create the ButtonBox ~~~~~~~~
self.dialogButtonBox = QDialogButtonBox(QDialogButtonBox.Cancel | QDialogButtonBox.Help)
self.dialogButtonBox.setOrientation(Qt.Horizontal)
self.import_button = self.dialogButtonBox.addButton(self.dialogButtonBox.Ok)
self.import_button.setText('Import Annotations')
# Action buttons
self.toggle_checkmarks_button = self.dialogButtonBox.addButton('Clear All', QDialogButtonBox.ActionRole)
self.toggle_checkmarks_button.setObjectName('toggle_checkmarks_button')
scb_text = 'Show match status'
if self.show_confidence_colors:
scb_text = "Hide match status"
self.show_confidence_button = self.dialogButtonBox.addButton(scb_text, QDialogButtonBox.ActionRole)
self.show_confidence_button.setObjectName('confidence_button')
if self.show_confidence_colors:
self.show_confidence_button.setIcon(get_icon('images/matches_hide.png'))
else: