    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Qt 4.0 is Out!</title>
        <link>https://members.accu.org/index.php/articles/827</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + CVu Journal Vol 17, #4 - Aug 2005</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c95/">174</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-95/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+95/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Qt 4.0 is Out!</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 August 2005 05:00:00 +01:00 or Wed, 03 August 2005 05:00:00 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
</div>
<p>Qt 4.0, the latest major version of Qt, is now available for
download. Like previous Qt releases, Qt 4.0's primary goal is to
allow C++ developers to create readable, maintainable,
cross-platform GUI applications that look native on all platforms.
Beyond that, the focus has been to make Qt even easier to learn and
use, to increase Qt's performance, and to make multithreaded
programming easier.</p>
<p>In the previous instalment of this series on GUI programming
with Qt, we presented the new set of collection classes introduced
with version 4.0. In this article, we will concentrate on some of
Qt 4.0's architectural changes and on its powerful 2D drawing
capabilities. But first, a note on licensing.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e26" id="d0e26"></a>Qt's
Dual-Licensing</h2>
</div>
<p>Starting with Qt 4, the Windows version of Qt is available both
under a commercial license and under the GNU General Public License
(GPL), extending Qt's Open Source offer to cover all platforms
supported by Qt. This means that if you want to build commercial
applications using Qt, you must buy a commercial licence from
Trolltech; if you want to build Open Source programs for
Unix/Linux, Windows or Mac OS X, you can download the Qt Open
Source Edition from http://www.trolltech.com/. Time-limited
evaluation versions are available for commercial evaluators.</p>
<p>The availability of a Qt/Windows Open Source Edition this year
is the last brick in the construction of our successful
dual-licensing business model. In the early days, Qt/X11 was
available as a binary-only package to Open Source
developers-notably the developers of the K Desktop Environment
(KDE) for Linux/Unix. The table below shows how we have made our
licensing more flexible and extended it to more platforms through
the years.</p>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;50%&quot;&gt;
&lt;col width=&quot;50%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th>Year</th>
<th>Event</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td>1998</td>
<td>Qt/X11 is released under the Q Public License (QPL), an Open
Source license, to satisfy the needs of the KDE project</td>
</tr>
<tr>
<td>2000</td>
<td>Qt/ X11 is released under the GPL, in addition to the QPL,
making it possible to write GPL software using Qt</td>
</tr>
<tr>
<td>2000</td>
<td>Qt/Embedded is released under the GPL</td>
</tr>
<tr>
<td>2001</td>
<td>Qt/Windows version 2.3 is made available as a binary-only
package under a non-commercial license</td>
</tr>
<tr>
<td>2003</td>
<td>Qt/Mac is released under the GPL</td>
</tr>
<tr>
<td>2005</td>
<td>Qt/Windows is released under the GPL</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p>Other Trolltech products, notably Qt Script for Applications
(QSA) and Qtopia PDA Edition, are available under both commercial
and Open Source licences.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e74" id="d0e74"></a>Architectural
Changes</h2>
</div>
<p>Unlike previous Qt releases, Qt 4 is a collection of smaller
libraries:</p>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;50%&quot;&gt;
&lt;col width=&quot;50%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th>Library</th>
<th>Description</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td><tt class="filename">QtCore</tt></td>
<td>Core non-GUI functionality</td>
</tr>
<tr>
<td><tt class="filename">QtGui</tt></td>
<td>Core GUI functionality</td>
</tr>
<tr>
<td><tt class="filename">QtNetwork</tt></td>
<td>Network module</td>
</tr>
<tr>
<td><tt class="filename">QtOpenGL</tt></td>
<td>OpenGL module</td>
</tr>
<tr>
<td><tt class="filename">QtSql</tt></td>
<td>SQL module</td>
</tr>
<tr>
<td><tt class="filename">QtXml</tt></td>
<td>XML module</td>
</tr>
<tr>
<td><tt class="filename">Qt3Support</tt></td>
<td>Qt 3 compatibility classes</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p><tt class="filename">QtCore</tt> contains tool classes like
<tt class="classname">QString</tt>, <tt class=
"classname">QList</tt>, and <tt class="classname">QFile</tt>, as
well as kernel classes like <tt class="classname">QObject</tt> and
<tt class="classname">QTimer</tt>. The <tt class=
"classname">QApplication</tt> class has been refactored so that it
can be used in non-GUI applications. It is split into <tt class=
"classname">QCoreApplication</tt> (in <tt class=
"filename">QtCore</tt>) and <tt class="classname">QApplication</tt>
(in <tt class="filename">QtGui</tt>). This split makes it possible
to develop server applications using Qt without linking in any
unnecessary GUI-related code and without requiring GUI-related
system libraries to be present on the target machine (e.g. Xlib on
X11, Carbon on Mac OS X).</p>
<p>In addition, Qt 4 provides an extension library that
applications based on Qt 3 called <tt class=
"filename">Qt3Support</tt>, that Qt applications can link against.
This allows for more compatibility than ever before, without
bloating Qt.</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Classes that have been replaced by a different class with the
same name, such as <tt class="classname">QListView</tt>, and
classes that no longer exist in Qt 4 are available with a 3 in
their name (e.g., <tt class="classname">Q3ListView</tt>, <tt class=
"classname">Q3Accel</tt>).</p>
</li>
<li>
<p>Other classes provide compatibility functions. Most of these are
implemented inline, so that they don't bloat the Qt libraries.</p>
</li>
</ul>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e185" id="d0e185"></a>New
Technologies</h2>
</div>
<p>Qt 4 introduces the following core technologies:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Tulip, a new set of template container classes.</p>
</li>
<li>
<p>Arthur, the Qt 4 painting framework.</p>
</li>
<li>
<p>Interview, a model/view architecture for item views.</p>
</li>
<li>
<p>Scribe, the Unicode text renderer with a public API for
performing low-level text layout.</p>
</li>
<li>
<p>Mainwindow, a modern action-based mainwindow, toolbar, menu, and
docking architecture.</p>
</li>
</ul>
</div>
<p>Qt 4 also includes the new Qt Designer user interface design
tool, which can be integrated with popular IDEs. In addition, the
following modules have been significantly improved since Qt 3:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>fully cross-platform accessibility module, with support for the
emerging SP-API Unix standard in addition to Microsoft and Mac
Accessibility.</p>
</li>
<li>
<p>The SQL module, which is now based on the Interview model/view
framework.</p>
</li>
<li>
<p>The network module, with better support for UDP and synchronous
sockets.</p>
</li>
<li>
<p>The style API, which is now decoupled from the widgets, meaning
that you can draw any user interface element on any device (widget,
pixmap, etc.).</p>
</li>
<li>
<p>Enhanced thread support, with signal-slot connections across
threads and per-thread event loops.</p>
</li>
<li>
<p>A new resource system for embedding images and other resource
files into the application executable.</p>
</li>
</ul>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e227" id="d0e227"></a>Arthur: The
New Paint System</h2>
</div>
<p>Qt 4 features a brand new paint subsystem, codenamed Arthur,
that takes advantage of advances in 2D graphics support on modern
window systems and the increased speed of desktop computers. Arthur
introduces support for antialiasing, alpha blending, gradient
filling, vector paths, and more. In this section, will show how to
use these new features to make Qt applications look nicer.</p>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e232" id=
"d0e232"></a>Antialiasing</h3>
</div>
<p>Aliasing when painting on a fixed-resolution device (such as a
screen) is a visual distortion that occurs when the edges of a
shape are converted into pixels. <i class=
"firstterm">Antialiasing</i> is a technique that reduces aliasing
by using different colour intensities on the edges.</p>
<div class="c3"><img src="/var/uploads/journals/resources/qt4_aa_line.png" align=
"middle"></div>
<p>Antialiased shapes are usually more pleasant to look at. They
can give the impression of a higher resolution than the screen
actually uses, and make adjacent edges and intersection points
clearer.</p>
<div class="c3"><img src="/var/uploads/journals/resources/qt4_aa_isect.png" align=
"middle"></div>
<p>Qt 3 already supported antialiasing for screen fonts on systems
that support it. Qt 4 adds supports for the other drawing shapes
(lines, polygons, ellipses, etc).</p>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e246" id="d0e246"></a>Alpha
Blending</h2>
</div>
<p><i class="firstterm">Alpha blending</i> is the process of
compositing pixels with semi-transparency. This is done by
extending the RGB triplet with an extra component, the &quot;alpha
channel&quot;, that specifies the level of transparency. The image below
shows a semi-transparent selection rectangle.</p>
<p><span class="inlinemediaobject"><img src=
"/var/uploads/journals/resources/i_selectionrect_qt4.png" align="left"></span>In Qt 3,
only QImage and QPixmap supported alpha blending. QImage could
support an 8-bit alpha channel and QPainter recognised this;
QPixmap preserved the alpha channel for pixmaps that were created
from QImages.</p>
<p>In Qt 4, QPainter supports alpha blending for all drawing
operations, for filling, stroking, and text rendering. To make this
possible, an alpha channel was added to QColor. For example, here's
how we would draw a semi-transparent selection rectangle &agrave;
la Windows XP:</p>
<pre class="programlisting">
painter.setPen(QColor(0, 0, 255, 191));
painter.setBrush(QColor(0, 0, 255, 63));
painter.drawRect(rect);
</pre>
<p>The fourth arguments to the QColor constructors specify the
alpha channel. The alpha values extend from 0 (fully transparent)
to 255 (opaque). In our example, the outline is 75% opaque and the
fill is 25% opaque.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e264" id="d0e264"></a>Gradient
Filling</h2>
</div>
<p><i class="firstterm">Gradient fills</i> are defined by the
interpolation between two or more colours, as opposed to a solid
fill, which consists of a uniform colour. In Qt 4, they are
implemented as a new QBrush fill pattern. For example:</p>
<pre class="programlisting">
QLinearGradient gradient(0, 0, 200, 100);
gradient.setColorAt(0.0, Qt::red);
gradient.setColorAt(1.0, Qt::blue);
painter.setBrush(gradient);
painter.drawEllipse(0, 0, 200, 100);
</pre>
<p>The code snippet defines a linear gradient fill that extends
from red at (0, 0) to blue at (200, 100). The colours at points in
between are interpolated linearly; points beyond the extremities
are filled with the nearest extremity's colour. The points are
expressed in logical painter coordinates. In addition to linear
gradients, Qt 4 also supports radial and conical gradients.</p>
<p>This feature makes it easy to create visually pleasing effects
such as shading on buttons. It can also be used in combination with
alpha blending to fade colours in and out. For example, the
following code snippet draws a gradient-filled rectangle on top of
a pixmap to fade it out:</p>
<pre class="programlisting">
QRect rect = pixmap.rect();
painter.drawPixmap(rect, pixmap);

QColor transparent(255, 255, 255, 0);
QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
gradient.setColorAt(0.0, transparent);
gradient.setColorAt(1.0, Qt::white);
painter.fillRect(rect, gradient);
</pre></div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e279" id="d0e279"></a>Floating
Point Based Painting</h2>
</div>
<div class="c3"><img src="/var/uploads/journals/resources/i_gradient_pixmap_qT4.png"
align="middle"></div>
<p><tt class="classname">QPainter</tt> in Qt 4 introduces a
floating point based API in addition to the existing integer-based
API. Classes like <tt class="classname">QPoint</tt>, <tt class=
"classname">QSize</tt>, and <tt class="classname">QRect</tt> are
now complemented by float-based classes such as <tt class=
"classname">QPointF</tt>, <tt class="classname">QSizeF</tt>, and
<tt class="classname">QRectF</tt>.</p>
<p>This feature is often used in combination with antialiasing to
increase the perceived resolution of what can be seen on screen. To
illustrate this, we will study the example of concentric circles
with alternating odd-even diameters.</p>
<p>The image on the left is drawn using <tt class=
"classname">QPainter</tt>'s <tt class="type">int</tt>-based API.
The image in the middle is drawn using the new float-based API. The
image on the right uses the float-based API together with
antialiasing.</p>
<div class="c3"><img src="/var/uploads/journals/resources/i_circles_qt4.png" align=
"middle"></div>
<p>The circles with an even diameter on the left image don't have
exactly the same centre point as the circles with an odd diameter;
there is a half pixel offset between the odd circles' center and
the even circles' centre. With the float-based API, we can specify
&quot;half pixel&quot; coordinates, and with antialiasing, we get circles
that look more accurate. Another benefit of using floating point
coordinates is that you can work in arbitrary resolutions.
Previously, if you wanted to plot floating point data, you
typically had to scale the coordinates and convert them to
integers.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e318" id="d0e318"></a>Painter
Paths</h2>
</div>
<p>Qt 4 introduces support for painter paths through the <tt class=
"classname">QPainterPath</tt> class. A <i class="firstterm">painter
path</i> (also called &quot;vector path&quot;) is a vectorial specification
of a shape. Painter paths are the ultimate drawing primitive, in
the sense that any shape (rectangle, ellipse, spline, etc.) or
combination of shapes can be expressed as a path. <tt class=
"classname">QPainter</tt> uses painter paths internally when
talking to the underlying paint engine.</p>
<p>A path specifies both an outline and an area. <tt class=
"methodname">QPainter::drawPath()</tt> draws the outline using the
current pen and fills the area with the current brush. Paths can
also be used for clipping using QPainter::setClipPath().</p>
<p>For many applications, the basic drawing operations provided by
<tt class="classname">QPainter</tt> (<tt class=
"methodname">drawRect()</tt>, <tt class=
"methodname">drawEllipse()</tt>, etc.) are sufficient. Applications
with more advanced 2D graphics, such as CAD applications, might use
<tt class="classname">QPainterPath</tt> to represent their
graphical data. <tt class="classname">QPainterPath</tt> can also be
used to create scalable icons or more complex clip areas than are
possible with <tt class="classname">QRegion</tt>.</p>
<div class="c3"><img src="/var/uploads/journals/resources/i_path_examples_qt4.png" align=
"middle"></div>
<p>A painter path is composed of two primitive elements: straight
lines and cubic B&eacute;zier curves. You can compose shapes by
connecting primitive elements together. A single path can contain
multiple shapes, or subpaths.</p>
<p>You can create paths using the basic functions <tt class=
"methodname">moveTo()</tt>, <tt class="methodname">lineTo()</tt>,
and <tt class="methodname">curveTo()</tt>. For example:</p>
<pre class="programlisting">
QPainterPath path;
path.moveTo(10, 10);
path.lineTo(20, 10);
path.curveTo(30, 20, 15, 15, 10, 20);
</pre>
<p>You can call <tt class="methodname">moveTo()</tt> at any time to
start a new subpath, and <tt class="methodname">closeSubpath()</tt>
to connect the first and last points of the current subpath.
<tt class="classname">QPainterPath</tt> also provides convenience
functions for commonly used shapes: <tt class=
"methodname">addRect()</tt>, <tt class=
"methodname">addEllipse()</tt>, <tt class=
"methodname">addPolygon()</tt>, <tt class=
"methodname">addText()</tt>, and <tt class=
"methodname">addRegion()</tt>.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e399" id="d0e399"></a>Advanced Text
Rendering</h2>
</div>
<p>In this last section, we will combine antialiasing, gradient
filling, and painter paths to render the word &quot;Arthur&quot; in a cool
way.</p>
<div class="c3"><img src="/var/uploads/journals/resources/arthur_qt4.png" align=
"middle"></div>
<p>We start by setting up the painter to use antialiasing and by
erasing the background:</p>
<pre class="programlisting">
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.fillRect(rect(), Qt::white);
</pre>
<p>We create a <tt class="classname">QPainterPath</tt> object that
corresponds to the outline and area of the text &quot;Arthur&quot; in
200-point Times:</p>
<pre class="programlisting">
QFont timesFont(&quot;Times&quot;, 200);
timesFont.setStyleStrategy(QFont::ForceOutline);

QPainterPath path;
path.addText(0, 200, timesFont, &quot;Arthur&quot;);
</pre>
<p>We fill the painter path's area with a gradient fill:</p>
<pre class="programlisting">
QLinearGradient pathGradient(0, 0, 0, 210);
pathGradient.setColorAt(0.0, QColor(219, 238, 188));
pathGraident.setColorAt(1.0, QColor(59, 156, 69));
painter.fillPath(path, pathBrush);
</pre>
<p>Finally, we use the <tt class=
"classname">QPainterPathStroker</tt> class to create a 2-pixel
thick painter path for the outline and fill it with a somewhat
darker gradient fill:</p>
<pre class="programlisting">
QPainterPathStroker stroker;
stroker.setWidth(2);
stroker.setJoinStyle(Qt::RoundJoin);
QPainterPath stroke = stroker.createStroke(path);

QLinearGradient strokeGradient(0, 0, 0, 210);
strokeGradient.setColorAt(0.0, QColor(150, 170, 140));
strokeGradient.setColorAt(1.0, QColor(0, 100, 20));
painter.fillPath(stroke, strokeBrush);
</pre>
<p>This is just a quick overview of the possibilities offered by
Arthur. Check out the Arthur demos in Qt's demos directory for some
mind-blowing effects.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
