<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000;"><div>hi all<br>i have problem with QPrintPreviewDialog() i made GUI with qt-designer to print text based on QtextEdit <br><br>when i click the button pre_print a QPrintPreviewDialog appear with print Preview of textedit <br><br>all of that good until i close the dialog and change the textedit text and Preview again i found Preview of <br>the old text instead of the new text and i have to change the page from portrait landscape to update it<br><br>any idea how to fix this<br><br>the p2.py :<br>=========<br># -*- coding: utf-8 -*-<br><br># Form implementation generated from reading ui file 'p2.ui'<br>#<br># Created: Thu Dec 11 09:24:22 2008<br># by: PyQt4 UI code generator 4.4.4<br>#<br># WARNING! All changes made in this file will be
lost!<br><br>from PyQt4 import QtCore, QtGui<br><br>class Ui_printerprinter(object):<br> def setupUi(self, printerprinter):<br> printerprinter.setObjectName("printerprinter")<br> printerprinter.setWindowModality(QtCore.Qt.WindowModal)<br> printerprinter.resize(471, 412)<br> self.centralwidget = QtGui.QWidget(printerprinter)<br> self.centralwidget.setObjectName("centralwidget")<br> self.pre_print = QtGui.QPushButton(self.centralwidget)<br> self.pre_print.setGeometry(QtCore.QRect(140, 20, 191, 51))<br> self.pre_print.setObjectName("pre_print")<br> self.textEdit =
QtGui.QTextEdit(self.centralwidget)<br> self.textEdit.setGeometry(QtCore.QRect(30, 90, 411, 241))<br> self.textEdit.setObjectName("textEdit")<br> self.exit = QtGui.QPushButton(self.centralwidget)<br> self.exit.setGeometry(QtCore.QRect(130, 350, 201, 41))<br> self.exit.setObjectName("exit")<br> printerprinter.setCentralWidget(self.centralwidget)<br><br> self.retranslateUi(printerprinter)<br> QtCore.QObject.connect(self.exit, QtCore.SIGNAL("clicked()"), printerprinter.close)<br> QtCore.QMetaObject.connectSlotsByName(printerprinter)<br><br> def retranslateUi(self,
printerprinter):<br> printerprinter.setWindowTitle(QtGui.QApplication.translate("printerprinter", "printer printer printer", None, QtGui.QApplication.UnicodeUTF8))<br> self.pre_print.setText(QtGui.QApplication.translate("printerprinter", "pre print", None, QtGui.QApplication.UnicodeUTF8))<br> self.exit.setText(QtGui.QApplication.translate("printerprinter", "exit", None, QtGui.QApplication.UnicodeUTF8))<br>-------------------------------------------------------------------------<br><br>the main program test2.py :<br>=====================<br># -*- coding: utf-8 -*-<br>#-------------------------------------------- import ---------------------------------------<br>from PyQt4.QtCore import *<br>from PyQt4.QtGui import *<br>from datetime import date<br>from p2 import *<br>import string<br>import sys,os,glob,re<br>import
codecs<br>import encodings<br>import chardet<br>from chardet.universaldetector import UniversalDetector<br>#--------------------------------------------------------------------------------------------<br><br>class printall(QMainWindow):<br> def __init__(self, parent=None):<br> QWidget.__init__(self, parent)<br> self.ui=Ui_printerprinter()<br> self.ui.setupUi(self)<br> <br> <br> self.preview = QPrintPreviewDialog()<br> self.preview.resize(800, 600)<br> <br> self.connect(self.preview,SIGNAL("paintRequested (QPrinter
*)"),self.what)<br> self.connect(self.ui.pre_print,SIGNAL("clicked ()"), self.ppreview)<br> <br> def what(self,other):<br> self.other=other<br> asd=((self.ui.textEdit.toPlainText()).split('\n'))<br> self.preview.autoFillBackground()<br> painter = QPainter()<br> painter.begin(other)<br> x=0<br> for s in asd:<br> print s #test if signal emit when close the dialog and open it again<br> if x ==
0:<br> pass<br> else:<br> other.newPage()<br> x=1<br> #painter.setPen(QColor(168, 34, 3)) # change colore<br> painter.setFont(QFont('Decorative', 25)) # change font<br> painter.drawText(100,100,s) # printing
point<br> painter.end()<br> <br> <br> <br> def ppreview(self):<br> print "working"<br> self.preview.exec_()<br> <br> <br> <br>#----------------------------------------- calling for main and graphic ---------------------------------<br>if __name__ == '__main__':<br> app=QApplication(sys.argv)<br> myapp=printall()<br> myapp.show()<br>
sys.exit(app.exec_())<br>#--------------------------------------------------------------------------------------------------------<br>-------------------------------------------------------------------------<br><br><br><br><br></div></div><br>
</body></html>