本文整理汇总了Python中PyQt5.QtWidgets.QTableView.itemDelegate方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.itemDelegate方法的具体用法?Python QTableView.itemDelegate怎么用?Python QTableView.itemDelegate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.itemDelegate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import itemDelegate [as 别名]
#.........这里部分代码省略.........
self.setWindowTitle("Pixelator")
self.resize(640, 480)
def chooseImage(self):
fileName, _ = QFileDialog.getOpenFileName(self, "Choose an Image",
self.currentPath, '*')
if fileName:
self.openImage(fileName)
def openImage(self, fileName):
image = QImage()
if image.load(fileName):
self.model.setImage(image)
if not fileName.startswith(':/'):
self.currentPath = fileName
self.setWindowTitle("%s - Pixelator" % self.currentPath)
self.printAction.setEnabled(True)
self.updateView()
def printImage(self):
if self.model.rowCount(QModelIndex()) * self.model.columnCount(QModelIndex()) > 90000:
answer = QMessageBox.question(self, "Large Image Size",
"The printed image may be very large. Are you sure that "
"you want to print it?",
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.No:
return
printer = QPrinter(QPrinter.HighResolution)
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle("Print Image")
if dlg.exec_() != QDialog.Accepted:
return
painter = QPainter()
painter.begin(printer)
rows = self.model.rowCount(QModelIndex())
columns = self.model.columnCount(QModelIndex())
sourceWidth = (columns+1) * ItemSize
sourceHeight = (rows+1) * ItemSize
painter.save()
xscale = printer.pageRect().width() / float(sourceWidth)
yscale = printer.pageRect().height() / float(sourceHeight)
scale = min(xscale, yscale)
painter.translate(printer.paperRect().x()+printer.pageRect().width()/2,
printer.paperRect().y()+printer.pageRect().height()/2)
painter.scale(scale, scale)
painter.translate(-sourceWidth/2, -sourceHeight/2)
option = QStyleOptionViewItem()
parent = QModelIndex()
progress = QProgressDialog("Printing...", "Cancel", 0, rows, self)
progress.setWindowModality(Qt.ApplicationModal)
y = ItemSize / 2.0
for row in range(rows):
progress.setValue(row)
QApplication.processEvents()
if progress.wasCanceled():
break
x = ItemSize / 2.0
for column in range(columns):
option.rect = QRect(x, y, ItemSize, ItemSize)
self.view.itemDelegate().paint(painter, option,
self.model.index(row, column, parent))
x += ItemSize
y += ItemSize
progress.setValue(rows)
painter.restore()
painter.end()
if progress.wasCanceled():
QMessageBox.information(self, "Printing canceled",
"The printing process was canceled.", QMessageBox.Cancel)
def showAboutBox(self):
QMessageBox.about(self, "About the Pixelator example",
"This example demonstrates how a standard view and a custom\n"
"delegate can be used to produce a specialized "
"representation\nof data in a simple custom model.")
def updateView(self):
self.view.resizeColumnsToContents()
self.view.resizeRowsToContents()