本文整理汇总了Python中PyQt5.Qt.QTableView.setModel方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setModel方法的具体用法?Python QTableView.setModel怎么用?Python QTableView.setModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QTableView
的用法示例。
在下文中一共展示了QTableView.setModel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialise
# 需要导入模块: from PyQt5.Qt import QTableView [as 别名]
# 或者: from PyQt5.Qt.QTableView import setModel [as 别名]
def initialise (self, univers):
model = QStandardItemModel (3,1)
i = 0
for faction in univers.faction_list :
item = QStandardItem(faction.name)
item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled);
item.setData(QtCore.Qt.Unchecked, QtCore.Qt.CheckStateRole);
model.setItem(i, 0, item)
i = i + 1
combo = QComboBox()
combo.setModel(model)
list_v = QListView()
list_v.setModel(model)
table = QTableView()
table.setModel(model)
container = QWidget()
containerLayout = QVBoxLayout()
container.setLayout(containerLayout)
containerLayout.addWidget(combo)
containerLayout.addWidget(list_v)
containerLayout.addWidget(table)
示例2: AnnotatedBooksDialog
# 需要导入模块: from PyQt5.Qt import QTableView [as 别名]
# 或者: from PyQt5.Qt.QTableView import setModel [as 别名]
class AnnotatedBooksDialog(SizePersistedDialog):
'''
This dialog is shown when the user fetches or imports books
self.fetch_single_annotations controls checkmark display, behavior of fetch button
'''
if isosx:
FONT = QFont('Monaco', 11)
elif iswindows:
FONT = QFont('Lucida Console', 9)
elif islinux:
FONT = QFont('Monospace', 9)
FONT.setStyleHint(QFont.TypeWriter)
def __init__(self, parent, book_list, get_annotations_as_HTML, source):
self.opts = parent.opts
self.parent = parent
self.get_annotations_as_HTML = get_annotations_as_HTML
self.show_confidence_colors = self.opts.prefs.get('annotated_books_dialog_show_confidence_as_bg_color', True)
self.source = source
# QDialog.__init__(self, parent=self.opts.gui)
SizePersistedDialog.__init__(self, self.opts.gui, 'Annotations plugin:import annotations dialog')
self.setWindowTitle(u'Import Annotations')
self.setWindowIcon(self.opts.icon)
self.l = QVBoxLayout(self)
self.setLayout(self.l)
self.perfect_width = 0
from calibre_plugins.annotations.appearance import default_timestamp
friendly_timestamp_format = plugin_prefs.get('appearance_timestamp_format', default_timestamp)
# Are we collecting News clippings?
collect_news_clippings = self.opts.prefs.get('cfg_news_clippings_checkbox', False)
news_clippings_destination = self.opts.prefs.get('cfg_news_clippings_lineEdit', None)
# Populate the table data
self.tabledata = []
for book_data in book_list:
enabled = QCheckBox()
enabled.setChecked(True)
# last_annotation sorts by timestamp
last_annotation = SortableTableWidgetItem(
strftime(friendly_timestamp_format,
localtime(book_data['last_update'])),
book_data['last_update'])
# reader_app sorts case-insensitive
reader_app = SortableTableWidgetItem(
book_data['reader_app'],
book_data['reader_app'].upper())
# title, author sort by title_sort, author_sort
if not book_data['title_sort']:
book_data['title_sort'] = book_data['title']
title = SortableTableWidgetItem(
book_data['title'],
book_data['title_sort'].upper())
if not book_data['author_sort']:
book_data['author_sort'] = book_data['author']
author = SortableTableWidgetItem(
book_data['author'],
book_data['author_sort'].upper())
genres = book_data['genre'].split(', ')
if 'News' in genres and collect_news_clippings:
cid = get_clippings_cid(self, news_clippings_destination)
confidence = 5
else:
cid, confidence = parent.generate_confidence(book_data)
# List order matches self.annotations_header
this_book = [
book_data['uuid'],
book_data['book_id'],
book_data['genre'],
enabled,
reader_app,
title,
author,
last_annotation,
book_data['annotations'],
confidence]
self.tabledata.append(this_book)
self.tv = QTableView(self)
self.l.addWidget(self.tv)
self.annotations_header = ['uuid', 'book_id', 'genre', '', 'Reader App', 'Title',
'Author', 'Last Annotation', 'Annotations', 'Confidence']
self.ENABLED_COL = 3
self.READER_APP_COL = 4
self.TITLE_COL = 5
self.AUTHOR_COL = 6
self.LAST_ANNOTATION_COL = 7
self.CONFIDENCE_COL = 9
columns_to_center = [8]
self.tm = MarkupTableModel(self, columns_to_center=columns_to_center)
self.tv.setModel(self.tm)
self.tv.setShowGrid(False)
#.........这里部分代码省略.........
示例3: OpdsDialog
# 需要导入模块: from PyQt5.Qt import QTableView [as 别名]
# 或者: from PyQt5.Qt.QTableView import setModel [as 别名]
class OpdsDialog(QDialog):
def __init__(self, gui, icon, do_user_config):
QDialog.__init__(self, gui)
self.gui = gui
self.do_user_config = do_user_config
self.db = gui.current_db.new_api
# The model for the book list
self.model = OpdsBooksModel(None, self.dummy_books(), self.db)
self.searchproxymodel = QSortFilterProxyModel(self)
self.searchproxymodel.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.searchproxymodel.setFilterKeyColumn(-1)
self.searchproxymodel.setSourceModel(self.model)
self.layout = QGridLayout()
self.setLayout(self.layout)
self.setWindowTitle('OPDS Client')
self.setWindowIcon(icon)
labelColumnWidths = []
self.opdsUrlLabel = QLabel('OPDS URL: ')
self.layout.addWidget(self.opdsUrlLabel, 0, 0)
labelColumnWidths.append(self.layout.itemAtPosition(0, 0).sizeHint().width())
config.convertSingleStringOpdsUrlPreferenceToListOfStringsPreference()
self.opdsUrlEditor = QComboBox(self)
self.opdsUrlEditor.activated.connect(self.opdsUrlEditorActivated)
self.opdsUrlEditor.addItems(prefs['opds_url'])
self.opdsUrlEditor.setEditable(True)
self.opdsUrlEditor.setInsertPolicy(QComboBox.InsertAtTop)
self.layout.addWidget(self.opdsUrlEditor, 0, 1, 1, 3)
self.opdsUrlLabel.setBuddy(self.opdsUrlEditor)
buttonColumnNumber = 7
buttonColumnWidths = []
self.about_button = QPushButton('About', self)
self.about_button.setAutoDefault(False)
self.about_button.clicked.connect(self.about)
self.layout.addWidget(self.about_button, 0, buttonColumnNumber)
buttonColumnWidths.append(self.layout.itemAtPosition(0, buttonColumnNumber).sizeHint().width())
# Initially download the catalogs found in the root catalog of the URL
# selected at startup. Fail quietly on failing to open the URL
catalogsTuple = self.model.downloadOpdsRootCatalog(self.gui, self.opdsUrlEditor.currentText(), False)
print catalogsTuple
firstCatalogTitle = catalogsTuple[0]
self.currentOpdsCatalogs = catalogsTuple[1] # A dictionary of title->feedURL
self.opdsCatalogSelectorLabel = QLabel('OPDS Catalog:')
self.layout.addWidget(self.opdsCatalogSelectorLabel, 1, 0)
labelColumnWidths.append(self.layout.itemAtPosition(1, 0).sizeHint().width())
self.opdsCatalogSelector = QComboBox(self)
self.opdsCatalogSelector.setEditable(False)
self.opdsCatalogSelectorModel = QStringListModel(self.currentOpdsCatalogs.keys())
self.opdsCatalogSelector.setModel(self.opdsCatalogSelectorModel)
self.opdsCatalogSelector.setCurrentText(firstCatalogTitle)
self.layout.addWidget(self.opdsCatalogSelector, 1, 1, 1, 3)
self.download_opds_button = QPushButton('Download OPDS', self)
self.download_opds_button.setAutoDefault(False)
self.download_opds_button.clicked.connect(self.download_opds)
self.layout.addWidget(self.download_opds_button, 1, buttonColumnNumber)
buttonColumnWidths.append(self.layout.itemAtPosition(1, buttonColumnNumber).sizeHint().width())
# Search GUI
self.searchEditor = QLineEdit(self)
self.searchEditor.returnPressed.connect(self.searchBookList)
self.layout.addWidget(self.searchEditor, 2, buttonColumnNumber - 2, 1, 2)
self.searchButton = QPushButton('Search', self)
self.searchButton.setAutoDefault(False)
self.searchButton.clicked.connect(self.searchBookList)
self.layout.addWidget(self.searchButton, 2, buttonColumnNumber)
buttonColumnWidths.append(self.layout.itemAtPosition(2, buttonColumnNumber).sizeHint().width())
# The main book list
self.library_view = QTableView(self)
self.library_view.setAlternatingRowColors(True)
self.library_view.setModel(self.searchproxymodel)
self.library_view.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
self.library_view.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
self.library_view.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)
self.library_view.setSelectionBehavior(QAbstractItemView.SelectRows)
self.resizeAllLibraryViewLinesToHeaderHeight()
self.library_view.resizeColumnsToContents()
self.layout.addWidget(self.library_view, 3, 0, 3, buttonColumnNumber + 1)
self.hideNewsCheckbox = QCheckBox('Hide Newspapers', self)
self.hideNewsCheckbox.clicked.connect(self.setHideNewspapers)
self.hideNewsCheckbox.setChecked(prefs['hideNewspapers'])
self.layout.addWidget(self.hideNewsCheckbox, 6, 0, 1, 3)
self.hideBooksAlreadyInLibraryCheckbox = QCheckBox('Hide books already in library', self)
self.hideBooksAlreadyInLibraryCheckbox.clicked.connect(self.setHideBooksAlreadyInLibrary)
self.hideBooksAlreadyInLibraryCheckbox.setChecked(prefs['hideBooksAlreadyInLibrary'])
#.........这里部分代码省略.........