本文整理汇总了Python中PyQt5.Qt.QTableView.setSortingEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setSortingEnabled方法的具体用法?Python QTableView.setSortingEnabled怎么用?Python QTableView.setSortingEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QTableView
的用法示例。
在下文中一共展示了QTableView.setSortingEnabled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PluginUpdaterDialog
# 需要导入模块: from PyQt5.Qt import QTableView [as 别名]
# 或者: from PyQt5.Qt.QTableView import setSortingEnabled [as 别名]
class PluginUpdaterDialog(SizePersistedDialog):
initial_extra_size = QSize(350, 100)
forum_label_text = _('Plugin homepage')
def __init__(self, gui, initial_filter=FILTER_UPDATE_AVAILABLE):
SizePersistedDialog.__init__(self, gui, 'Plugin Updater plugin:plugin updater dialog')
self.gui = gui
self.forum_link = None
self.zip_url = None
self.model = None
self.do_restart = False
self._initialize_controls()
self._create_context_menu()
try:
display_plugins = read_available_plugins(raise_error=True)
except Exception:
display_plugins = []
import traceback
error_dialog(self.gui, _('Update Check Failed'),
_('Unable to reach the plugin index page.'),
det_msg=traceback.format_exc(), show=True)
if display_plugins:
self.model = DisplayPluginModel(display_plugins)
self.proxy_model = DisplayPluginSortFilterModel(self)
self.proxy_model.setSourceModel(self.model)
self.plugin_view.setModel(self.proxy_model)
self.plugin_view.resizeColumnsToContents()
self.plugin_view.selectionModel().currentRowChanged.connect(self._plugin_current_changed)
self.plugin_view.doubleClicked.connect(self.install_button.click)
self.filter_combo.setCurrentIndex(initial_filter)
self._select_and_focus_view()
else:
self.filter_combo.setEnabled(False)
# Cause our dialog size to be restored from prefs or created on first usage
self.resize_dialog()
def _initialize_controls(self):
self.setWindowTitle(_('User plugins'))
self.setWindowIcon(QIcon(I('plugins/plugin_updater.png')))
layout = QVBoxLayout(self)
self.setLayout(layout)
title_layout = ImageTitleLayout(self, 'plugins/plugin_updater.png',
_('User plugins'))
layout.addLayout(title_layout)
header_layout = QHBoxLayout()
layout.addLayout(header_layout)
self.filter_combo = PluginFilterComboBox(self)
self.filter_combo.setMinimumContentsLength(20)
self.filter_combo.currentIndexChanged[int].connect(self._filter_combo_changed)
la = QLabel(_('Filter list of &plugins')+':', self)
la.setBuddy(self.filter_combo)
header_layout.addWidget(la)
header_layout.addWidget(self.filter_combo)
header_layout.addStretch(10)
# filter plugins by name
la = QLabel(_('Filter by &name')+':', self)
header_layout.addWidget(la)
self.filter_by_name_lineedit = QLineEdit(self)
la.setBuddy(self.filter_by_name_lineedit)
self.filter_by_name_lineedit.setText("")
self.filter_by_name_lineedit.textChanged.connect(self._filter_name_lineedit_changed)
header_layout.addWidget(self.filter_by_name_lineedit)
self.plugin_view = QTableView(self)
self.plugin_view.horizontalHeader().setStretchLastSection(True)
self.plugin_view.setSelectionBehavior(QAbstractItemView.SelectRows)
self.plugin_view.setSelectionMode(QAbstractItemView.SingleSelection)
self.plugin_view.setAlternatingRowColors(True)
self.plugin_view.setSortingEnabled(True)
self.plugin_view.setIconSize(QSize(28, 28))
layout.addWidget(self.plugin_view)
details_layout = QHBoxLayout()
layout.addLayout(details_layout)
forum_label = self.forum_label = QLabel('')
forum_label.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard)
forum_label.linkActivated.connect(self._forum_label_activated)
details_layout.addWidget(QLabel(_('Description')+':', self), 0, Qt.AlignLeft)
details_layout.addWidget(forum_label, 1, Qt.AlignRight)
self.description = QLabel(self)
self.description.setFrameStyle(QFrame.Panel | QFrame.Sunken)
self.description.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.description.setMinimumHeight(40)
self.description.setWordWrap(True)
layout.addWidget(self.description)
self.button_box = QDialogButtonBox(QDialogButtonBox.Close)
self.button_box.rejected.connect(self.reject)
self.finished.connect(self._finished)
self.install_button = self.button_box.addButton(_('&Install'), QDialogButtonBox.AcceptRole)
self.install_button.setToolTip(_('Install the selected plugin'))
self.install_button.clicked.connect(self._install_clicked)
self.install_button.setEnabled(False)
#.........这里部分代码省略.........
示例2: AnnotatedBooksDialog
# 需要导入模块: from PyQt5.Qt import QTableView [as 别名]
# 或者: from PyQt5.Qt.QTableView import setSortingEnabled [as 别名]
#.........这里部分代码省略.........
# 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:
self.show_confidence_button.setIcon(get_icon('images/matches_show.png'))
self.preview_button = self.dialogButtonBox.addButton('Preview', QDialogButtonBox.ActionRole)
self.preview_button.setObjectName('preview_button')
self.dialogButtonBox.clicked.connect(self.show_annotated_books_dialog_clicked)
self.l.addWidget(self.dialogButtonBox)