[PyQt] QPrintDialog (pyqt4)
jaybstory
jaybstory at yahoo.com
Sat Feb 20 04:10:15 GMT 2010
Thank you very much.
Russell Valentine wrote:
>
> You can do something like this if it is a function of your MainWindow.
> self as a argument in grabWidget is your baseWidget, like a QMainWindow
> for example. No doubt you would have to make sure it fits on the page
> though and resize it as needed.
>
> def goPrinter(self):
> printer=QtGui.QPrinter()
> dialog = QtGui.QPrintDialog(printer, self)
> if(dialog.exec_() != QtGui.QDialog.Accepted):
> return
> p=QtGui.QPixmap.grabWidget(self)
> printLabel = QtGui.QLabel()
> printLabel.setPixmap(p)
> painter = QtGui.QPainter(printer)
> printLabel.render(painter)
> painter.end()
>
>
> jaybstory wrote:
>> I understand your example for printing Labels. I'm wondering if there is
>> a
>> way to just print the entire GUI? I tried to do this, but its not
>> correct:
>>
>> def printd(self):
>> printer=QtGui.QPrinter()
>> dialog = QtGui.QPrintDialog(printer, self)
>> if(dialog.exec_() != QtGui.QDialog.Accepted):
>> return
>> printGUI = QtGui.QTabWidget
>> painter = QtGui.QPainter(printer)
>> printGUI.render(painter)
>> painter.end()
>>
>> maybe I'm not understanding the way render works? Or is this the wrong
>> approach all together? Thank you.
>>
>>
>> Russell Valentine wrote:
>>> Joi Barnett wrote:
>>>> thank you for the reply,
>>>>
>>>> do you have an example of how to use QPrinter in python?
>>>
>>> I didn't have one, but I just made one really quick. Very simple
>>> example. I Cc'd the list in case anyone else had anything to add.
>>>
>>>
>>> from PyQt4 import QtGui, QtCore
>>>
>>> class MainWindow(QtGui.QMainWindow):
>>> def __init__(self, app):
>>> QtGui.QMainWindow.__init__(self)
>>> self.app=app
>>> self.label=QtGui.QLabel("Print test")
>>> self.setCentralWidget(self.label)
>>> def goPrinter(self):
>>> printer=QtGui.QPrinter()
>>> dialog = QtGui.QPrintDialog(printer, self)
>>> if(dialog.exec_() != QtGui.QDialog.Accepted):
>>> return
>>> printLabel = QtGui.QLabel("Hello my printer.")
>>> painter = QtGui.QPainter(printer)
>>> printLabel.render(painter)
>>> painter.end()
>>>
>>> if __name__ == "__main__":
>>> import sys
>>> app = QtGui.QApplication(sys.argv)
>>> window=MainWindow(app)
>>> window.show()
>>> QtCore.QTimer.singleShot(1000, window.goPrinter)
>>> #ui.show()
>>> sys.exit(app.exec_())
>>>
>>> _______________________________________________
>>> PyQt mailing list PyQt at riverbankcomputing.com
>>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>>
>>>
>>
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>
--
View this message in context: http://old.nabble.com/QPrintDialog-%28pyqt4%29-tp27619288p27663457.html
Sent from the PyQt mailing list archive at Nabble.com.
More information about the PyQt
mailing list