本文整理汇总了Python中PyQt4.QtGui.QPrinter.height方法的典型用法代码示例。如果您正苦于以下问题:Python QPrinter.height方法的具体用法?Python QPrinter.height怎么用?Python QPrinter.height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QPrinter
的用法示例。
在下文中一共展示了QPrinter.height方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ui_py_de
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import height [as 别名]
#.........这里部分代码省略.........
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.textEdit.sizePolicy().hasHeightForWidth())
self.textEdit.setSizePolicy(sizePolicy)
self.textEdit.setObjectName(newTextEditName)
self.tablayout.addWidget(self.textEdit, 0, 0, 1, 1)
#####################################
## Functions for menu button actions
#####################################
def openFile(self):
fileName = QFileDialog.getOpenFileName()
print fileName
index = fileName.lastIndexOf("/")
newFileName = fileName[index+1:]
print newFileName
self.createTab(py_de, "", newFileName)
self.textEdit.setText(open(fileName).read())
def printFile(self): # Needs some work...
printDialog = QPrintDialog(self.printer, py_de)
if printDialog.exec_() == QDialog.Accepted:
margin = 10
pageNum = 1
yPos = 0
printJob = QPainter()
printJob.begin(self.printer)
printJob.setFont(self.font)
fm = printJob.fontMetrics()
for i in range(self.textEdit.lines()):
if margin + yPos > self.printer.height() - margin:
pageNum += 1
self.printer.newPage()
yPos = 0
printJob.drawText(margin, # X
margin + yPos, # Y
self.printer.width(), # Width
self.printer.height(),# Height
QtCore.Qt.AlignTop, # Alignment
self.textEdit.text(i - 1)# The text to print
)
yPos += fm.lineSpacing()
printJob.end
def saveFile(self):
fileName = QFileDialog.getSaveFileName()
f = open(fileName, "w")
f.write(self.textEdit.text())
def saveAsFile(self):
QKeySequence(self.textEdit.trUtf8("Ctrl+Shft+S", "File|Save As"))
fileName = QFileDialog.getSaveFileName()
f = open(fileName, "w")
f.write(self.textEdit.text())
def goToLine(self):
maxLine = str(self.textEdit.lines())
newLineNumber, ok = QInputDialog.getInteger(self.centralwidget,
"Go to line",
"Line number: (1, " + maxLine+")")
if ok:
newLineNumber -= 1 # Convert from 1-based to 0-based
self.textEdit.ensureLineVisible(newLineNumber)