本文整理汇总了Python中PyQt5.QtWidgets.QTableView.setModel方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setModel方法的具体用法?Python QTableView.setModel怎么用?Python QTableView.setModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.setModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def __init__(self):
super().__init__()
self.setWindowTitle('Phone Book.')
self.name = QLineEdit()
self.number = QLineEdit()
entry = QFormLayout()
entry.addRow(QLabel('Name'), self.name)
entry.addRow(QLabel('Number'), self.number)
buttons = QHBoxLayout()
button = QPushButton('&Add')
button.clicked.connect(self._addEntry)
buttons.addWidget(button)
button = QPushButton('&Update')
button.clicked.connect(self._updateEntry)
buttons.addWidget(button)
button = QPushButton('&Delete')
button.clicked.connect(self._deleteEntry)
buttons.addWidget(button)
dataDisplay = QTableView()
dataDisplay.setModel(PhoneDataModel())
layout = QVBoxLayout()
layout.addLayout(entry)
layout.addLayout(buttons)
layout.addWidget(dataDisplay)
self.setLayout(layout)
self.show()
示例2: GroupWidget
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [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)
示例3: main
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def main(args):
app = QApplication(args)
page = QSplitter()
data = Model(1000, 10, page)
selections = QItemSelectionModel(data)
table = QTableView()
table.setModel(data)
table.setSelectionModel(selections)
table.horizontalHeader().setSectionsMovable(True)
table.verticalHeader().setSectionsMovable(True)
# Set StaticContents to enable minimal repaints on resizes.
table.viewport().setAttribute(Qt.WA_StaticContents)
page.addWidget(table)
tree = QTreeView()
tree.setModel(data)
tree.setSelectionModel(selections)
tree.setUniformRowHeights(True)
tree.header().setStretchLastSection(False)
tree.viewport().setAttribute(Qt.WA_StaticContents)
# Disable the focus rect to get minimal repaints when scrolling on Mac.
tree.setAttribute(Qt.WA_MacShowFocusRect, False)
page.addWidget(tree)
list = QListView()
list.setModel(data)
list.setSelectionModel(selections)
list.setViewMode(QListView.IconMode)
list.setSelectionMode(QAbstractItemView.ExtendedSelection)
list.setAlternatingRowColors(False)
list.viewport().setAttribute(Qt.WA_StaticContents)
list.setAttribute(Qt.WA_MacShowFocusRect, False)
page.addWidget(list)
page.setWindowIcon(QIcon(images_dir + '/interview.png'))
page.setWindowTitle("Interview")
page.show()
return app.exec_()
示例4: __init__
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def __init__(self, parent):
super(Table, self).__init__()
self.parent = parent
tablemodel = TableModel(self.parent.dictpar[self.parent.code]['vphi'], self)
tableview = QTableView()
tableview.setModel(tablemodel)
示例5: createView
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def createView(title, model):
view = QTableView()
view.setModel(model)
view.setItemDelegate(QSqlRelationalDelegate(view))
view.setWindowTitle(title)
return view
示例6: MyWin
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
class MyWin(QWidget):
def __init__(self, mydb):
super(MyWin, self).__init__()
main_lt = QVBoxLayout()
self.view = QTableView()
main_lt.addWidget(self.view)
self.view.setWindowTitle("Table Model (View 1)")
self.view.setSelectionBehavior(QAbstractItemView.SelectRows)
self.mydb = mydb
button = QPushButton("Join")
button.clicked.connect(self.merge)
main_lt.addWidget(button)
button = QPushButton("Exit")
button.clicked.connect(lambda: exit())
main_lt.addWidget(button)
self.setLayout(main_lt)
self.setWindowTitle('QT1')
def set_model(self):
self.view.setModel(self.mydb.get_model())
def merge(self):
ind_list = self.view.selectedIndexes()
out = list(self.view.model().data(i) for i in ind_list)
out = [out[i] for i in range(len(out)) if i % 2 == 0]
if len(out) < 2:
return
self.mydb.merge(out)
mb = QMessageBox()
mb.setText('Merged %s' % str(out))
mb.exec_()
self.set_model()
示例7: UdpLogReceiver
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
class UdpLogReceiver(QWidget):
"""
Log events generated by python logging objects.
"""
def __init__(self, parent=None):
super().__init__(parent)
self._model = LogRecordModel()
filter_model = QSortFilterProxyModel()
filter_model.setSourceModel(self._model)
filter_model.setFilterKeyColumn(3)
self.msg_filter = QLineEdit()
self.log_view = QTableView()
self.log_view.setModel(filter_model)
header = self.log_view.horizontalHeader()
#header.setSectionResizeMode(header.Stretch)
header.setStretchLastSection(True)
self.status_label = QLabel()
# Connect signals:
self.msg_filter.textChanged.connect(filter_model.setFilterFixedString)
# Make nice layout:
layout = QVBoxLayout(self)
layout.addWidget(self.msg_filter)
layout.addWidget(self.log_view)
layout.addWidget(self.status_label)
# Attach udp server:
self._udpServer = UdpHandler(self._model)
self._model.stats_changed.connect(self.status_label.setText)
示例8: __init__
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def __init__(self, tableName, parent=None):
super(TableEditor, self).__init__(parent)
self.model = QSqlTableModel(self)
self.model.setTable(tableName)
self.model.setEditStrategy(QSqlTableModel.OnManualSubmit)
self.model.select()
self.model.setHeaderData(0, Qt.Horizontal, "ID")
self.model.setHeaderData(1, Qt.Horizontal, "First name")
self.model.setHeaderData(2, Qt.Horizontal, "Last name")
view = QTableView()
view.setModel(self.model)
submitButton = QPushButton("Submit")
submitButton.setDefault(True)
revertButton = QPushButton("&Revert")
quitButton = QPushButton("Quit")
buttonBox = QDialogButtonBox(Qt.Vertical)
buttonBox.addButton(submitButton, QDialogButtonBox.ActionRole)
buttonBox.addButton(revertButton, QDialogButtonBox.ActionRole)
buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole)
submitButton.clicked.connect(self.submit)
revertButton.clicked.connect(self.model.revertAll)
quitButton.clicked.connect(self.close)
mainLayout = QHBoxLayout()
mainLayout.addWidget(view)
mainLayout.addWidget(buttonBox)
self.setLayout(mainLayout)
self.setWindowTitle("Cached Table")
示例9: TestWidget
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
class TestWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
vbox = QVBoxLayout(self)
self.view = QTableView()
self.model = Model(self.view)
self.view.setModel(self.model)
vbox.addWidget(self.view)
示例10: _makeTable
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def _makeTable(self, model):
table = QTableView(self)
table.setModel(model)
table.hideColumn(0)
table.setShowGrid(False)
subListDelegate = SubListItemDelegate()
table.setItemDelegateForColumn(1, subListDelegate)
table.setItemDelegateForColumn(2, subListDelegate)
table.horizontalHeader().setSectionResizeMode(3, QHeaderView.Stretch)
table.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeToContents)
return table
示例11: setModel
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def setModel(self, model):
QTableView.setModel(self, model)
# The model needs to be set to set header stuff
hheader = self.horizontalHeader()
hheader.setHighlightSections(False)
hheader.setStretchLastSection(False)
hheader.resizeSection(0, 100)
hheader.setSectionResizeMode(0, QHeaderView.Fixed)
hheader.setSectionResizeMode(1, QHeaderView.Stretch)
hheader.setSectionResizeMode(2, QHeaderView.Stretch)
vheader = self.verticalHeader()
vheader.setVisible(False)
vheader.setDefaultSectionSize(18)
示例12: setModel
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def setModel(self, model):
QTableView.setModel(self._table, model)
self._table.setSelectionModel(model._selectionModel)
if model.rowCount() > 0:
self.setCurrentIndex(self.PAGE_LISTVIEW)
else:
self.setCurrentIndex(self.PAGE_EMPTY)
model.rowsInserted.connect(self._onRowsChanged)
model.rowsRemoved.connect(self._onRowsChanged)
self.model=model
self._setListViewLook()
示例13: SetupUI
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def SetupUI(self, w):
info("SetupUI")
# Search bar
lblName = QLabel('Search')
lblResults = QLabel('Results')
# Plugin table
ledtName = QLineEdit()
tblResults = QTableView()
tblResultsModel = PluginTableModel(self.available_plugins, Plugin.SQLITE_COLUMNS, w)
tblResults.setModel( tblResultsModel )
tblResults.horizontalHeader().setStretchLastSection(True)
tblResults.verticalHeader().setVisible(False)
tblResults.resizeColumnsToContents()
tblResults.setSortingEnabled(True)
tblResults.setFont( QFont("Courier New", 8) )
tblResults.setShowGrid(False)
## event handlers
ledtName.textChanged.connect(self.OnSearchFieldChange)
# Button row
btnUpdate = QPushButton("Refresh Plugins List")
btnInstall = QPushButton("Install")
## event handlers
btnUpdate.clicked.connect(self.RefreshPluginsList)
btnInstall.clicked.connect(self.InstallSelected)
grid = QGridLayout()
grid.addWidget(lblName, 1, 0)
grid.addWidget(ledtName, 1, 1)
grid.addWidget(lblResults, 2, 0)
grid.addWidget(tblResults, 2, 1, 5, 1)
vbox = QVBoxLayout()
vbox.addStretch(1)
vbox.addWidget(btnUpdate)
vbox.addWidget(btnInstall)
wButtons = QWidget()
wButtons.setLayout(vbox)
grid.addWidget(wButtons, 5, 1, 4, 1)
w.setLayout(grid)
return
示例14: viewTable
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
class viewTable(QDialog):
def __init__(self, parent=None):
fileName = filedialog.askopenfilename()
if fileName != '':
k = fileName.rfind("/")
self.parent = parent
self.parent.statusbar.showMessage("Opening dataset...")
QWidget.__init__(self,parent)
self.setWindowFlags(Qt.Window)
self.setObjectName("dialog1")
self.setGeometry(100,100,400,400)
self.setWindowTitle(fileName[k+1:])
self.setWindowIcon(QIcon('NSlogo.png'))
self.model = QStandardItemModel(self)
with open(fileName, "r") as fileInput:
for row in csv.reader(fileInput, delimiter='\t'):
items = [
QStandardItem(field)
for field in row
]
self.model.appendRow(items)
self.tableView = QTableView(self)
self.tableView.setModel(self.model)
self.layoutVertical = QVBoxLayout(self)
self.layoutVertical.addWidget(self.tableView)
self.parent = parent
self.showMaximized()
self.show()
self.parent.ui.logOutput.append("VIEWED:")
print("VIEWED:")
self.parent.ui.logOutput.append(" " + str(fileName.split('/')[-1]))
print(" " + str(fileName.split('/')[-1]))
def closeEvent(self, event):
self.model.clear()
self.parent.ui.logOutput.append("")
self.parent.statusbar.showMessage("Welcome back!")
示例15: setupViews
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setModel [as 别名]
def setupViews(self):
splitter = QSplitter()
table = QTableView()
self.pieChart = PieView()
splitter.addWidget(table)
splitter.addWidget(self.pieChart)
splitter.setStretchFactor(0, 0)
splitter.setStretchFactor(1, 1)
table.setModel(self.model)
self.pieChart.setModel(self.model)
self.selectionModel = QItemSelectionModel(self.model)
table.setSelectionModel(self.selectionModel)
self.pieChart.setSelectionModel(self.selectionModel)
table.horizontalHeader().setStretchLastSection(True)
self.setCentralWidget(splitter)