[PyQt] QPrintPreviewDialog() problem

BLACK HAWK el_sakir12 at yahoo.com
Thu Dec 11 11:16:28 GMT 2008


hi all
i have problem with QPrintPreviewDialog() i made GUI with qt-designer to print text based on QtextEdit 

when i click the button pre_print a QPrintPreviewDialog appear with print Preview of textedit 

all of that good until i close the dialog and change the textedit text and Preview again i found Preview  of 
the old text instead of the new text and i have to change the page from portrait landscape to update it

any idea how to fix this

the p2.py :
=========
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'p2.ui'
#
# Created: Thu Dec 11 09:24:22 2008
#      by: PyQt4 UI code generator 4.4.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_printerprinter(object):
    def setupUi(self, printerprinter):
        printerprinter.setObjectName("printerprinter")
        printerprinter.setWindowModality(QtCore.Qt.WindowModal)
        printerprinter.resize(471, 412)
        self.centralwidget = QtGui.QWidget(printerprinter)
        self.centralwidget.setObjectName("centralwidget")
        self.pre_print = QtGui.QPushButton(self.centralwidget)
        self.pre_print.setGeometry(QtCore.QRect(140, 20, 191, 51))
        self.pre_print.setObjectName("pre_print")
        self.textEdit = QtGui.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(30, 90, 411, 241))
        self.textEdit.setObjectName("textEdit")
        self.exit = QtGui.QPushButton(self.centralwidget)
        self.exit.setGeometry(QtCore.QRect(130, 350, 201, 41))
        self.exit.setObjectName("exit")
        printerprinter.setCentralWidget(self.centralwidget)

        self.retranslateUi(printerprinter)
        QtCore.QObject.connect(self.exit, QtCore.SIGNAL("clicked()"), printerprinter.close)
        QtCore.QMetaObject.connectSlotsByName(printerprinter)

    def retranslateUi(self, printerprinter):
        printerprinter.setWindowTitle(QtGui.QApplication.translate("printerprinter", "printer printer printer", None, QtGui.QApplication.UnicodeUTF8))
        self.pre_print.setText(QtGui.QApplication.translate("printerprinter", "pre print", None, QtGui.QApplication.UnicodeUTF8))
        self.exit.setText(QtGui.QApplication.translate("printerprinter", "exit", None, QtGui.QApplication.UnicodeUTF8))
-------------------------------------------------------------------------

the main program test2.py :
=====================
# -*- coding: utf-8 -*-
#-------------------------------------------- import ---------------------------------------
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from datetime import date
from p2 import *
import string
import sys,os,glob,re
import codecs
import encodings
import chardet
from chardet.universaldetector import UniversalDetector
#--------------------------------------------------------------------------------------------

class printall(QMainWindow):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.ui=Ui_printerprinter()
        self.ui.setupUi(self)
        
        
        self.preview = QPrintPreviewDialog()
        self.preview.resize(800, 600)
        
        self.connect(self.preview,SIGNAL("paintRequested (QPrinter *)"),self.what)
        self.connect(self.ui.pre_print,SIGNAL("clicked ()"), self.ppreview)
        
    def what(self,other):
        self.other=other
        asd=((self.ui.textEdit.toPlainText()).split('\n'))
        self.preview.autoFillBackground()
        painter = QPainter()
        painter.begin(other)
        x=0
        for s in asd:
            print s #test if signal emit when close the dialog and open it again
            if x == 0:
                pass
            else:
                other.newPage()
            x=1
            #painter.setPen(QColor(168, 34, 3))             # change colore
            painter.setFont(QFont('Decorative', 25))       # change font
            painter.drawText(100,100,s)                    # printing point
        painter.end()
        
        
        
    def ppreview(self):
        print "working"
        self.preview.exec_()
        
        
        
#----------------------------------------- calling for main and graphic ---------------------------------
if __name__ == '__main__':
    app=QApplication(sys.argv)
    myapp=printall()
    myapp.show()
    sys.exit(app.exec_())
#--------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20081211/37ac56ff/attachment.html


More information about the PyQt mailing list