index.lxp@lxpwrap=c8100_252ehtm.htm

来自「GUI Programming with Python」· HTM 代码 · 共 317 行

HTM
317
字号
    <table border="0" cellspacing="0" cellpadding="3" width="100%"><tr><td>    <div align="center" id="bldcontent">      <a href="../default.htm"><img src="../images/opendocs.png" width="63" height="76" border="0"></a>      <br>      <div class="symbol">Your OpenSource Publisher&#153;</div>    </div>      </td></tr></table>    <div align="center" class="author">      	<a href="../products.lxp">Products</a>	&nbsp;|&nbsp;	<a href="../wheretobuy.lxp">Where to buy</a>	&nbsp;|&nbsp;	<a href="../bookstore.lxp">Retailers</a>	&nbsp;|&nbsp;	<a href="../faq.lxp">FAQ</a>	&nbsp;|&nbsp;        <a href="../writeforus.lxp">Write for Us.</a>        &nbsp;|&nbsp;        <a href="#contact">Contact Us.</a>  </div>    <table border="0" cellspacing="3" cellpadding="0" width="100%"><tr><td width="100%">      <div class="content">        <table border="0" cellspacing="2" cellpadding="0" width="100%"><tr><td width="100%">          <div align="center"><H4 CLASS="AUTHOR"><A NAME="AEN5">Boudewijn Rempt</A><br><a href="../../https@secure.linuxports.com/opendocs/default.htm"><img src=odpyqt125.png></a><br>ISBN: 0-97003300-4-4<br><a href="../../https@secure.linuxports.com/opendocs/default.htm">Available from bookstores everywhere or you can order it here.</a><p>You can download the source files for the book <a href="pyqtsrc.tgz">(code / eps) here.</a><hr></div>                    <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"><A accesskey="P" href="index.lxp@lxpwrap=x8095_252ehtm.htm">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><A accesskey="N" href="index.lxp@lxpwrap=x8141_252ehtm.htm">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1>Chapter 24. Printing</A></H1><DIVCLASS="TOC"><DL><DT><B>Table of Contents</B></DT><DT><A href="index.lxp@lxpwrap=c8100_252ehtm.htm#AEN8115">The <TTCLASS="CLASSNAME">QPrinter</TT> class</A></DT><DT><A href="index.lxp@lxpwrap=x8141_252ehtm.htm">Adding printing to Kalam</A></DT><DT><A href="index.lxp@lxpwrap=x8148_252ehtm.htm">Putting ink to paper</A></DT><DT><A href="index.lxp@lxpwrap=x8207_252ehtm.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">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"><A accesskey="P" href="index.lxp@lxpwrap=x8095_252ehtm.htm">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="H" href="index.lxp@lxpwrap=book1_252ehtm">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><A accesskey="N" href="index.lxp@lxpwrap=x8141_252ehtm.htm">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Conclusion</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="U" href="index.lxp@lxpwrap=p4627_252ehtm.htm">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Adding printing to Kalam</TD></TR></TABLE></DIV></BODY></HTML>      </td>      </tr>      </table>      </td>    </tr>  </table>      

⌨️ 快捷键说明

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