⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c8100.htm

📁 GUI Programming with Python
💻 HTM
字号:
<HTML><HEAD><TITLE>Printing</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.72"><LINKREL="HOME"TITLE="GUI Programming with Python: QT Edition"HREF="book1.htm"><LINKREL="UP"TITLE="Creating real applications with PyQt"HREF="p4627.htm"><LINKREL="PREVIOUS"TITLE="Conclusion"HREF="x8095.htm"><LINKREL="NEXT"TITLE="Adding printing to Kalam"HREF="x8141.htm"></HEAD><BODYCLASS="CHAPTER"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GUI Programming with Python: QT Edition</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="x8095.htm"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="x8141.htm"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="CH17">Chapter 24. Printing</A></H1><DIVCLASS="TOC"><DL><DT><B>Table of Contents</B></DT><DT><AHREF="c8100.htm#AEN8115">The <TTCLASS="CLASSNAME">QPrinter</TT> class</A></DT><DT><AHREF="x8141.htm">Adding printing to Kalam</A></DT><DT><AHREF="x8148.htm">Putting ink to paper</A></DT><DT><AHREF="x8207.htm">Conclusion</A></DT></DL></DIV><P>Printing: a subject that strikes fear into    the heart of even the most stalwart developer&#8212;and with good    reason. Getting a user's application data neatly on paper demands    a lot of skill.</P><P>Common problems include different printer    capabilities, differences between fonts on screen and on the    printer, differing paper sizes, and platform differences in    getting the output to the printer.</P><P>PyQt brings a measure of relief to some of    these problems, though not to all. It provides you with the    <TTCLASS="CLASSNAME">QPrinter</TT> object, which is a type of    <TTCLASS="CLASSNAME">QPaintDevice</TT> that has a built-in common    dialog for printer settings. This takes care of most problems    associated with font handling and printer capabilities.  With Qt 3    you can even send TrueType fonts to the printer. The hard    work&#8212;the layout of the page for paper&#8212;is still your    job.</P><P>Printing on Unix/X11 requires creating    PostScript files and sending them to lpr. On Windows systems you    can use the built-in printer drivers. On a Unix system you can    always chicken out; if your application data is plain text or    source code, you can spool it directly to the printer, or via a    pretty-printing program such as a2ps.</P><P>For the moment, we will not pursue that    option, and instead use <TTCLASS="CLASSNAME">QPrinter</TT> to add    printing capabilities to <SPANCLASS="APPLICATION">Kalam</SPAN>.</P><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="AEN8115">The <TTCLASS="CLASSNAME">QPrinter</TT> class</A></H1><P>Generally speaking, there will be only one      active printer attached to a user's system. This means that we      will keep a single reference to a      <TTCLASS="CLASSNAME">QPrinter</TT> object. Therefore, we might as      well create the <TTCLASS="CLASSNAME">QPrinter</TT> in the      <TTCLASS="FUNCTION">__init__()</TT> method of the      <TTCLASS="CLASSNAME">KalamApp</TT> class.</P><PRECLASS="PROGRAMLISTING"># kalamapp.pyclass KalamApp(QMainWindow):    """KalamApp is the toplevel application window of the kalam unicode editor    application.    """    def __init__(self, *args):        apply(QMainWindow.__init__,(self, ) + args)        ...        # Create the printer object        self.printer = QPrinter()        ...    </PRE><P><TTCLASS="CLASSNAME">QPrinter</TT> is more      configurable than most <TTCLASS="CLASSNAME">QPaintDevices</TT>. You      can set the printer, printer driver, paper size, number of      copies to be printed, and so on. You can set those configuration      options programmatically, but some of them can also be changed      by the user. If you call the <TTCLASS="FUNCTION">setup()</TT> function on the      printer object, a printer setup dialog will popup:</P><DIVCLASS="MEDIAOBJECT"><P><DIVCLASS="CAPTION"><P>The printer setup dialog</P></DIV></P></DIV></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="x8095.htm"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="book1.htm"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="x8141.htm"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Conclusion</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="p4627.htm"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Adding printing to Kalam</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -