本文整理汇总了Python中PyQt5.QtWidgets.QTableWidget.model方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidget.model方法的具体用法?Python QTableWidget.model怎么用?Python QTableWidget.model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableWidget
的用法示例。
在下文中一共展示了QTableWidget.model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SpreadSheet
# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import model [as 别名]
#.........这里部分代码省略.........
# column 1
self.table.setItem(0, 1, SpreadSheetItem("Date"))
self.table.item(0, 1).setBackground(titleBackground)
self.table.item(0, 1).setToolTip("This column shows the purchase date, double click to change")
self.table.item(0, 1).setFont(titleFont)
self.table.setItem(1, 1, SpreadSheetItem("15/6/2006"))
self.table.setItem(2, 1, SpreadSheetItem("15/6/2006"))
self.table.setItem(3, 1, SpreadSheetItem("15/6/2006"))
self.table.setItem(4, 1, SpreadSheetItem("21/5/2006"))
self.table.setItem(5, 1, SpreadSheetItem("16/6/2006"))
self.table.setItem(6, 1, SpreadSheetItem("16/6/2006"))
self.table.setItem(7, 1, SpreadSheetItem("16/6/2006"))
self.table.setItem(8, 1, SpreadSheetItem("18/6/2006"))
self.table.setItem(9, 1, SpreadSheetItem())
self.table.item(9, 1).setBackground(Qt.lightGray)
# column 2
self.table.setItem(0, 2, SpreadSheetItem("Price"))
self.table.item(0, 2).setBackground(titleBackground)
self.table.item(0, 2).setToolTip("This column shows the price of the purchase")
self.table.item(0, 2).setFont(titleFont)
self.table.setItem(1, 2, SpreadSheetItem("150"))
self.table.setItem(2, 2, SpreadSheetItem("2350"))
self.table.setItem(3, 2, SpreadSheetItem("-14"))
self.table.setItem(4, 2, SpreadSheetItem("980"))
self.table.setItem(5, 2, SpreadSheetItem("5"))
self.table.setItem(6, 2, SpreadSheetItem("120"))
self.table.setItem(7, 2, SpreadSheetItem("300"))
self.table.setItem(8, 2, SpreadSheetItem("1240"))
self.table.setItem(9, 2, SpreadSheetItem())
self.table.item(9, 2).setBackground(Qt.lightGray)
# column 3
self.table.setItem(0, 3, SpreadSheetItem("Currency"))
self.table.item(0, 3).setBackgroundColor(titleBackground)
self.table.item(0, 3).setToolTip("This column shows the currency")
self.table.item(0, 3).setFont(titleFont)
self.table.setItem(1, 3, SpreadSheetItem("NOK"))
self.table.setItem(2, 3, SpreadSheetItem("NOK"))
self.table.setItem(3, 3, SpreadSheetItem("EUR"))
self.table.setItem(4, 3, SpreadSheetItem("EUR"))
self.table.setItem(5, 3, SpreadSheetItem("USD"))
self.table.setItem(6, 3, SpreadSheetItem("USD"))
self.table.setItem(7, 3, SpreadSheetItem("USD"))
self.table.setItem(8, 3, SpreadSheetItem("USD"))
self.table.setItem(9, 3, SpreadSheetItem())
self.table.item(9,3).setBackground(Qt.lightGray)
# column 4
self.table.setItem(0, 4, SpreadSheetItem("Ex. Rate"))
self.table.item(0, 4).setBackground(titleBackground)
self.table.item(0, 4).setToolTip("This column shows the exchange rate to NOK")
self.table.item(0, 4).setFont(titleFont)
self.table.setItem(1, 4, SpreadSheetItem("1"))
self.table.setItem(2, 4, SpreadSheetItem("1"))
self.table.setItem(3, 4, SpreadSheetItem("8"))
self.table.setItem(4, 4, SpreadSheetItem("8"))
self.table.setItem(5, 4, SpreadSheetItem("7"))
self.table.setItem(6, 4, SpreadSheetItem("7"))
self.table.setItem(7, 4, SpreadSheetItem("7"))
self.table.setItem(8, 4, SpreadSheetItem("7"))
self.table.setItem(9, 4, SpreadSheetItem())
self.table.item(9,4).setBackground(Qt.lightGray)
# column 5
self.table.setItem(0, 5, SpreadSheetItem("NOK"))
self.table.item(0, 5).setBackground(titleBackground)
self.table.item(0, 5).setToolTip("This column shows the expenses in NOK")
self.table.item(0, 5).setFont(titleFont)
self.table.setItem(1, 5, SpreadSheetItem("* C2 E2"))
self.table.setItem(2, 5, SpreadSheetItem("* C3 E3"))
self.table.setItem(3, 5, SpreadSheetItem("* C4 E4"))
self.table.setItem(4, 5, SpreadSheetItem("* C5 E5"))
self.table.setItem(5, 5, SpreadSheetItem("* C6 E6"))
self.table.setItem(6, 5, SpreadSheetItem("* C7 E7"))
self.table.setItem(7, 5, SpreadSheetItem("* C8 E8"))
self.table.setItem(8, 5, SpreadSheetItem("* C9 E9"))
self.table.setItem(9, 5, SpreadSheetItem("sum F2 F9"))
self.table.item(9,5).setBackground(Qt.lightGray)
def showAbout(self):
QMessageBox.about(self, "About Spreadsheet", """
<HTML>
<p><b>This demo shows use of <c>QTableWidget</c> with custom handling for
individual cells.</b></p>
<p>Using a customized table item we make it possible to have dynamic
output in different cells. The content that is implemented for this
particular demo is:
<ul>
<li>Adding two cells.</li>
<li>Subtracting one cell from another.</li>
<li>Multiplying two cells.</li>
<li>Dividing one cell with another.</li>
<li>Summing the contents of an arbitrary number of cells.</li>
</HTML>
""")
def print_(self):
printer = QPrinter(QPrinter.ScreenResolution)
dlg = QPrintPreviewDialog(printer)
view = PrintView()
view.setModel(self.table.model())
dlg.paintRequested.connect(view.print_)
dlg.exec_()
示例2: LabelAssistDialog
# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import model [as 别名]
#.........这里部分代码省略.........
box.show()
return
# Clear table
self.table.clearContents()
self.table.setRowCount(0)
self.table.setSortingEnabled(False)
self.progressBar.show()
self.computeButton.setEnabled(False)
def compute_features_for_frame(tIndex, t, features):
# Compute features and labels (called in parallel from request pool)
roi = [slice(None) for i in range(len(self.topLevelOperatorView.LabelImages.meta.shape))]
roi[tIndex] = slice(t, t+1)
roi = tuple(roi)
frame = self.topLevelOperatorView.SegmentationImages(roi).wait()
frame = frame.squeeze().astype(numpy.uint32, copy=False)
# Dirty trick: We don't care what we're passing here for the 'image' parameter,
# but vigra insists that we pass *something*, so we'll cast the label image as float32.
features[t] = vigra.analysis.extractRegionFeatures(frame.view(numpy.float32),
frame,
['Count'],
ignoreLabel=0)
tIndex = self.topLevelOperatorView.SegmentationImages.meta.axistags.index('t')
tMax = self.topLevelOperatorView.SegmentationImages.meta.shape[tIndex]
features = {}
labels = {}
def compute_all_features():
# Compute features in parallel
pool = RequestPool()
for t in range(tMax):
pool.add( Request( partial(compute_features_for_frame, tIndex, t, features) ) )
pool.wait()
# Compute labels
labels = self.topLevelOperatorView.LabelInputs([]).wait()
req = Request(compute_all_features)
req.notify_finished( partial(self._populateTable, features, labels) )
req.submit()
@threadRouted
def _populateTable(self, features, labels, *args):
self.progressBar.hide()
self.computeButton.setEnabled(True)
for time, feature in features.items():
# Insert row
rowNum = self.table.rowCount()
self.table.insertRow(self.table.rowCount())
# Get max and min object areas
areas = feature['Count']#objectFeatures['Standard Object Features']['Count']
maxObjArea = numpy.max(areas[numpy.nonzero(areas)])
minObjArea = numpy.min(areas[numpy.nonzero(areas)])
# Get number of labeled objects
labelNum = numpy.count_nonzero(labels[time])
# Load fram number
item = QTableWidgetItem(str(time))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.table.setItem(rowNum, 0, item)
# Load max object areas
item = QTableWidgetItemWithFloatSorting(str("{: .02f}".format(maxObjArea)))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.table.setItem(rowNum, 1, item)
# Load min object areas
item = QTableWidgetItemWithFloatSorting(str("{: .02f}".format(minObjArea)))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.table.setItem(rowNum, 2, item)
# Load label numbers
item = QTableWidgetItemWithFloatSorting(str("{: .01f}".format(labelNum)))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.table.setItem(rowNum, 3, item)
# Resize column size to fit dialog size
self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
# Sort by max object area
self.table.setSortingEnabled(True)
self.table.sortByColumn(1, Qt.DescendingOrder)
def _captureDoubleClick(self):
# Navigate to selected frame
index = self.table.selectedIndexes()[0]
frameStr = self.table.model().data(index).toString()
if frameStr:
frameNum = int(frameStr)
self.parent().editor.posModel.time = frameNum