index.lxp@lxpwrap=x5021_252ehtm.htm

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

HTM
258
字号
    <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>Keyboard accelerators</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="Actions: menus, toolbars and accelerators"HREF="c4807.htm"><LINKREL="PREVIOUS"TITLE="Toolbars"HREF="x4974.htm"><LINKREL="NEXT"TITLE="Setting an application icon"HREF="x5049.htm"></HEAD><BODYCLASS="SECT1"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=x4974_252ehtm.htm">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 13. Actions: menus, toolbars and accelerators</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><A accesskey="N" href="index.lxp@lxpwrap=x5049_252ehtm.htm">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1">Keyboard accelerators</A></H1><P>The old vi or Emacs lags amongst us know      this already, just as the WordPerfect veterans know: regardless      of what Rob Pike, designer of the Plan9 operating system, says,      using a keyboard can actually be preferable to grabbing the      mouse for every trifle. Giving the vast majority of interface      actions in your application a keyboard accelerator is therefore      a Good Thing, and is highly encouraged.</P><P>Note the subtle difference between a      keyboard accelerator and a keyboard shortcut. Shortcuts are      generally combinations of the Alt key and a letter. They are      indicated in menus and dialogs by an underscore, and created      by simply prefixing an ampersand (&#38;) to the shortcut      letter. Shortcuts only function in the context of a menu or      dialog box: that's why Alt-F generally opens the file menu,      but Alt-Q doesn't close the application unless the file menu      happens to be open. Accelerators are important and every      menu option and every widget on a dialog ought to be      associated with one.</P><P>Accelerators, on the other hand, are      generally combinations of CTRL and some other key (or,      for the WordPerfect-conditioned octopodi amongst us, all      modifiers together; CTRL-SHIFT-ALT-F12, anyone?). If the focus      of your application is on the document (or on a text field in a      dialog box), then your user will want to use shortcuts for      everything.</P><P>There are a number of standard      accelerators, such as CTRL-X for the cut action, but every      application is free to add to that store. You associate      accelerators with <TTCLASS="CLASSNAME">QAction</TT>s, with the      <TTCLASS="FUNCTION">setAccel</TT> function. For actions that are not      associated with <TTCLASS="CLASSNAME">QAction</TT>s, you can create      <TTCLASS="CLASSNAME">QAccel</TT> objects on their own, and connect      them to a slot of your choice.</P><P><TTCLASS="CLASSNAME">QAccel</TT> offers one      especially handy class method, <TTCLASS="FUNCTION">stringToKey</TT>,      which takes a string describing an accelerator and returns and      integer value that represents a key combination to PyQt. The      format is very clear: "Ctrl+O", for instance. Even better,      because this is a <SPAN><ICLASS="EMPHASIS">string</I></SPAN>, you can translate      this string using pygettext or PyQt's <TTCLASS="FUNCTION">tr()</TT>      to localize the keyboard shortcuts for different countries. This      is not possible if you use the Qt constants that represent keys,      such as <SPAN><ICLASS="EMPHASIS">Qt.CTRL + Qt.Key_O</I></SPAN>.</P></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=x4974_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=x5049_252ehtm.htm">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Toolbars</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="U" href="index.lxp@lxpwrap=c4807_252ehtm.htm">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Setting an application icon</TD></TR></TABLE></DIV></BODY></HTML>      </td>      </tr>      </table>      </td>    </tr>  </table>      

⌨️ 快捷键说明

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