<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™</div>
</div>
</td></tr></table>
<div align="center" class="author">
<a href="../products.lxp">Products</a>
|
<a href="../wheretobuy.lxp">Where to buy</a>
|
<a href="../bookstore.lxp">Retailers</a>
|
<a href="../faq.lxp">FAQ</a>
|
<a href="../writeforus.lxp">Write for Us.</a>
|
<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
>Creating themes with QStyle</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.72
"><LINK
REL="HOME"
TITLE="GUI Programming with Python: QT Edition"
HREF="book1.htm"><LINK
REL="UP"
TITLE="Gui Design in the Baroque Age"
HREF="c7878.htm"><LINK
REL="PREVIOUS"
TITLE="Faking it with bitmaps"
HREF="x7898.htm"><LINK
REL="NEXT"
TITLE="Drag and drop"
HREF="c8016.htm"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>GUI Programming with Python: QT Edition</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A accesskey="P" href="index.lxp@lxpwrap=x7898_252ehtm.htm">Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 22. Gui Design in the Baroque Age</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A accesskey="N" href="index.lxp@lxpwrap=c8016_252ehtm.htm">Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
>Creating themes with QStyle</A
></H1
><P
>We've just created a beautifully sculpted interface, with
all the highlights exactly right. Of course, the process lacked any
flexibility. Fortunately, PyQt offers complete access to the Qt
theming mechanism. Using this mechanism we can achieve almost the
same effect, but in a more flexible and generic manner. </P
><P
>The key class here is <TT
CLASS="CLASSNAME"
>QStyle</TT
>.
This class provides an enormous number of methods that are
used by Qt's widgets to express themselves on screen — and a
few hooks that you can use to intervene just before a widget
paints itself.
<TT
CLASS="CLASSNAME"
>QCommonStyle</TT
> is based on <TT
CLASS="CLASSNAME"
>QStyle</TT
>,
and implements most of
the actual drawing routines. On top of
<TT
CLASS="CLASSNAME"
>QCommonStyle</TT
> is a whole tree of styles
for Motif, Windows, MacOS-platinum, SGI and
CDE. A desktop environment like KDE adds a whole host of other
styles - and we can add one, too, once we have designed it.
</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
>Designing the style</A
></H2
><P
>Designing a successful widget style is an artistic
endeavor that calls for sensitive handling and an acute
awareness of usability principles, as can easily be seen from
the thousands of horrible styles available from websites like
www.themes.org. But then, designing a user interface calls for
the same expertise. That's the reason most software houses
employ interaction designers and graphic artists. Software
developers who don't have access to these specialists can
refer to the excellent books on interface design published by
Apple and Microsoft. These are the <SPAN
><I
CLASS="EMPHASIS"
>Macintosh Human
Interface Guidelines</I
></SPAN
>
(http://www.devworld.apple.com/techpubs/mac/HIGuidelines/HIGuidelines-2.html)
and <SPAN
><I
CLASS="EMPHASIS"
>Microsoft Guidelines for Interface
design</I
></SPAN
>, respectively. The Interface Hall of Shame
website (http://www.iarchitect.com/mshame.htm) has some
hilarious examples of interface design!</P
><P
>On the other hand, making something
<SPAN
><I
CLASS="EMPHASIS"
>look</I
></SPAN
> like something else is a lot easier.
For this project, I've pondered a few example styles
that would illustrate the capabilities of the
<TT
CLASS="CLASSNAME"
>QStyle</TT
> mechanism: the old Athena widget
look and feel, or the old ‘flat' MacOS look and feel. The new
Aqua style was right out, for legal reasons.
Perhaps the look of the rubber keyboard
or the old ZX-Spectrum? For my example, we'll try the old, flat MacOS look.
This one has the advantage of being visually simple. You can
complicate the implementation of a style enormously
by using complex gradients to fill buttons, or bitmaps
and masks to fill widget backgrounds. The
<TT
CLASS="CLASSNAME"
>QStyle</TT
> is flexible enough that you can
use anything the <TT
CLASS="CLASSNAME"
>QPainter</TT
> class offers
to paint your widgets. On the other hand, some parts are
exceedingly difficult to adapt, as we shall see.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
>Setting up</A
></H2
><P
>The system that is used to implement custom styles changed
completely between Qt 2 and Qt 3, which is a pity, because at
the time of writing this book the new styling system had not
been completely finished (and not wrapped for PyQt), but the
old system has been removed.</P
><P
>New styles are implemented by subclassing one of the
descendants of <TT
CLASS="CLASSNAME"
>QStyle</TT
> (this holds for
both systems).</P
><P
>Under the old system, most of the widget drawing code
would have been placed in the <TT
CLASS="FUNCTION"
>polish()</TT
>
and <TT
CLASS="FUNCTION"
>unpolish()</TT
> methods of the style
implementation.</P
><P
>The new system demands that you re-implement the
primitive drawing functions, such as
<TT
CLASS="FUNCTION"
>drawItem()</TT
>,
<TT
CLASS="FUNCTION"
>drawPrimitive()</TT
> or
<TT
CLASS="FUNCTION"
>drawComplexControl</TT
>.</P
><P
>In both cases, you can decide to either use bitmaps for
buttons and backgrounds. This is shown in the
<TT
CLASS="FILENAME"
>themes.py</TT
> example in your
<SPAN
CLASS="APPLICATION"
>BlackAdder</SPAN
> or
<SPAN
CLASS="APPLICATION"
>PyQt</SPAN
> distribution. Alternatively, you can
write your own drawing routines. It is surprising that
Python is fast enough to allow re-implementing the most basic
drawing routines.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
>A Qt 2 custom style</A
></H2
><DIV
CLASS="EXAMPLE"
></A
><P
><B
>Example 22-4. A Qt 2 custom style - a minimalist
implementation of the classic Mac style in PyQt.</B
></P
><PRE
CLASS="PROGRAMLISTING"
>#
# macstyle.py - A minimalist implementation of the Mac Classic style for PyQt
# and Qt 2.
# Use with styletester.py
#
from qt import *
import time
FALSE=0
TRUE=1
class MacStyle(QWindowsStyle):
def __init__(self):
QWindows
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
GUI Programming with Python (197个子文件)
qt-condensed.eps 843KB
ownership-condensed.eps 224KB
connection_button.eps 6KB
10.gif 926B
9.gif 919B
6.gif 917B
8.gif 915B
3.gif 914B
5.gif 912B
2.gif 907B
4.gif 907B
7.gif 903B
1.gif 890B
index.lxp@lxpwrap=x7947_252ehtm.htm 40KB
index.lxp@lxpwrap=c6351_252ehtm.htm 38KB
c6351.htm 36KB
index.lxp@lxpwrap=x6734_252ehtm.htm 35KB
index.lxp@lxpwrap=x4274_252ehtm.htm 35KB
default.htm 31KB
index.lxp@lxpwrap=x3738_252ehtm.htm 30KB
index.lxp@lxpwrap=x1807_252ehtm.htm 29KB
index.lxp@lxpwrap=x7601_252ehtm.htm 29KB
index.lxp@lxpwrap=x1408_252ehtm.htm 27KB
index.lxp@lxpwrap=x6082_252ehtm.htm 26KB
index.lxp@lxpwrap=x5469_252ehtm.htm 26KB
index.lxp@lxpwrap=x2183_252ehtm.htm 25KB
index.lxp@lxpwrap=c7391_252ehtm.htm 25KB
index.lxp@lxpwrap=x2976_252ehtm.htm 24KB
book1.htm 23KB
c7391.htm 23KB
index.lxp@lxpwrap=x1631_252ehtm.htm 22KB
index.lxp@lxpwrap=c4631_252ehtm.htm 21KB
index.lxp@lxpwrap=c1267_252ehtm.htm 20KB
index.lxp@lxpwrap=x7161_252ehtm.htm 20KB
c4631.htm 20KB
c1267.htm 19KB
index.lxp@lxpwrap=x2420_252ehtm.htm 19KB
index.lxp@lxpwrap=c6996_252ehtm.htm 18KB
index.lxp@lxpwrap=x2765_252ehtm.htm 18KB
index.lxp@lxpwrap=x3410_252ehtm.htm 17KB
index.lxp@lxpwrap=x3581_252ehtm.htm 17KB
c6996.htm 17KB
index.lxp@lxpwrap=x8418_252ehtm.htm 16KB
index.lxp@lxpwrap=c88_252ehtm.htm 16KB
index.lxp@lxpwrap=x5388_252ehtm.htm 16KB
index.lxp@lxpwrap=c653_252ehtm.htm 15KB
index.lxp@lxpwrap=x9022_252ehtm.htm 15KB
index.lxp@lxpwrap=c4807_252ehtm.htm 15KB
index.lxp@lxpwrap=c4079_252ehtm.htm 15KB
c88.htm 15KB
index.lxp@lxpwrap=c8212_252ehtm.htm 14KB
index.lxp@lxpwrap=x7295_252ehtm.htm 14KB
c653.htm 14KB
index.lxp@lxpwrap=a8647_252ehtm.htm 13KB
index.lxp@lxpwrap=x5339_252ehtm.htm 13KB
index.lxp@lxpwrap=x3270_252ehtm.htm 13KB
index.lxp@lxpwrap=a8743_252ehtm.htm 13KB
c4079.htm 13KB
c4807.htm 13KB
index.lxp@lxpwrap=x5798_252ehtm.htm 13KB
index.lxp@lxpwrap=x5968_252ehtm.htm 13KB
index.lxp@lxpwrap=c5584_252ehtm.htm 13KB
index.lxp@lxpwrap=x1214_252ehtm.htm 12KB
a8743.htm 12KB
index.lxp@lxpwrap=x2693_252ehtm.htm 11KB
index.lxp@lxpwrap=x719_252ehtm.htm 11KB
index.lxp@lxpwrap=x1149_252ehtm.htm 11KB
index.lxp@lxpwrap=x1067_252ehtm.htm 11KB
index.lxp@lxpwrap=x2104_252ehtm.htm 11KB
c5584.htm 11KB
index.lxp@lxpwrap=x327_252ehtm.htm 11KB
index.lxp@lxpwrap=x8949_252ehtm.htm 11KB
index.lxp@lxpwrap=r9791_252ehtm.htm 10KB
index.lxp@lxpwrap=x179_252ehtm.htm 10KB
index.lxp@lxpwrap=x823_252ehtm.htm 10KB
index.lxp@lxpwrap=x7898_252ehtm.htm 10KB
index.lxp@lxpwrap=b10472_252ehtm.htm 9KB
index.lxp@lxpwrap=x6300_252ehtm.htm 9KB
index.lxp@lxpwrap=x5722_252ehtm.htm 9KB
index.lxp@lxpwrap=x5255_252ehtm.htm 9KB
index.lxp@lxpwrap=c5064_252ehtm.htm 9KB
index.lxp@lxpwrap=c883_252ehtm.htm 9KB
index.lxp@lxpwrap=c8349_252ehtm.htm 9KB
index.lxp@lxpwrap=x9684_252ehtm.htm 9KB
index.lxp@lxpwrap=c5288_252ehtm.htm 9KB
index.lxp@lxpwrap=x8887_252ehtm.htm 9KB
index.lxp@lxpwrap=x9571_252ehtm.htm 9KB
index.lxp@lxpwrap=c8016_252ehtm.htm 9KB
index.lxp@lxpwrap=x9236_252ehtm.htm 9KB
index.lxp@lxpwrap=c1036_252ehtm.htm 9KB
index.lxp@lxpwrap=f26_252ehtm.htm 8KB
index.lxp@lxpwrap=x5879_252ehtm.htm 8KB
index.lxp@lxpwrap=x455_252ehtm.htm 8KB
index.lxp@lxpwrap=x5925_252ehtm.htm 8KB
index.lxp@lxpwrap=c2341_252ehtm.htm 8KB
index.lxp@lxpwrap=x5120_252ehtm.htm 8KB
index.lxp@lxpwrap=x2068_252ehtm.htm 8KB
index.lxp@lxpwrap=x5202_252ehtm.htm 8KB
index.lxp@lxpwrap=a8834_252ehtm.htm 7KB
c883.htm 7KB
共 197 条
- 1
- 2
资源评论
- Nacidar2020-10-29这个pyqt,里面是html
文森特houzy
- 粉丝: 2
- 资源: 55
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功