Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > d5e62c01ae8d1e579463c6a871dd44bf > files > 1136

qtbase5-doc-5.12.6-2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- coordsys.qdoc -->
  <title>Coordinate System | Qt GUI 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtgui-index.html">Qt GUI</a></td><td >Coordinate System</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtgui-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#rendering">Rendering</a></li>
<li class="level2"><a href="#logical-representation">Logical Representation</a></li>
<li class="level2"><a href="#aliased-painting">Aliased Painting</a></li>
<li class="level2"><a href="#anti-aliased-painting">Anti-aliased Painting</a></li>
<li class="level1"><a href="#transformations">Transformations</a></li>
<li class="level1"><a href="#window-viewport-conversion">Window-Viewport Conversion</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Coordinate System</h1>
<span class="subtitle"></span>
<!-- $$$coordsys.html-description -->
<div class="descr"> <a name="details"></a>
<p>The coordinate system is controlled by the <a href="qpainter.html">QPainter</a> class. Together with the <a href="qpaintdevice.html">QPaintDevice</a> and <a href="qpaintengine.html">QPaintEngine</a> classes, <a href="qpainter.html">QPainter</a> form the basis of Qt's painting system, Arthur. <a href="qpainter.html">QPainter</a> is used to perform drawing operations, <a href="qpaintdevice.html">QPaintDevice</a> is an abstraction of a two-dimensional space that can be painted on using a <a href="qpainter.html">QPainter</a>, and <a href="qpaintengine.html">QPaintEngine</a> provides the interface that the painter uses to draw onto different types of devices.</p>
<p>The <a href="qpaintdevice.html">QPaintDevice</a> class is the base class of objects that can be painted: Its drawing capabilities are inherited by the <a href="../qtwidgets/qwidget.html">QWidget</a>, <a href="qimage.html">QImage</a>, <a href="qpixmap.html">QPixmap</a>, <a href="qpicture.html">QPicture</a>, and <a href="qopenglpaintdevice.html">QOpenGLPaintDevice</a> classes. The default coordinate system of a paint device has its origin at the top-left corner. The <i>x</i> values increase to the right and the <i>y</i> values increase downwards. The default unit is one pixel on pixel-based devices and one point (1/72 of an inch) on printers.</p>
<p>The mapping of the logical <a href="qpainter.html">QPainter</a> coordinates to the physical <a href="qpaintdevice.html">QPaintDevice</a> coordinates are handled by <a href="qpainter.html">QPainter</a>'s transformation matrix, viewport and &quot;window&quot;. The logical and physical coordinate systems coincide by default. <a href="qpainter.html">QPainter</a> also supports coordinate transformations (e.g&#x2e; rotation and scaling).</p>
<a name="rendering"></a>
<h2 id="rendering">Rendering</h2>
<a name="logical-representation"></a>
<h3 id="logical-representation">Logical Representation</h3>
<p>The size (width and height) of a graphics primitive always correspond to its mathematical model, ignoring the width of the pen it is rendered with:</p>
<div class="table"><table class="generic">
 <tr valign="top" class="odd"><td ><img src="images/coordinatesystem-rect.png" alt="" /></td><td ><img src="images/coordinatesystem-line.png" alt="" /></td></tr>
<tr valign="top" class="even"><td ><a href="../qtcore/qrect.html">QRect</a>(1, 2, 6, 4)</td><td ><a href="../qtcore/qline.html">QLine</a>(2, 7, 6, 1)</td></tr>
</table></div>
<a name="aliased-painting"></a>
<h3 id="aliased-painting">Aliased Painting</h3>
<p>When drawing, the pixel rendering is controlled by the <a href="qpainter.html#RenderHint-enum">QPainter::Antialiasing</a> render hint.</p>
<p>The <a href="qpainter.html#RenderHint-enum">RenderHint</a> enum is used to specify flags to <a href="qpainter.html">QPainter</a> that may or may not be respected by any given engine. The <a href="qpainter.html#RenderHint-enum">QPainter::Antialiasing</a> value indicates that the engine should antialias edges of primitives if possible, i.e&#x2e; smoothing the edges by using different color intensities.</p>
<p>But by default the painter is <i>aliased</i> and other rules apply: When rendering with a one pixel wide pen the pixels will be rendered to the <i>right and below the mathematically defined points</i>. For example:</p>
<div class="table"><table class="generic">
 <tr valign="top" class="odd"><td ><img src="images/coordinatesystem-rect-raster.png" alt="" /></td><td ><img src="images/coordinatesystem-line-raster.png" alt="" /></td></tr>
<tr valign="top" class="even"><td ><pre class="cpp">

  <span class="type"><a href="qpainter.html">QPainter</a></span> painter(<span class="keyword">this</span>);

  painter<span class="operator">.</span>setPen(<span class="type"><a href="qt-sub-qtgui.html">Qt</a></span><span class="operator">::</span>darkGreen);
  painter<span class="operator">.</span>drawRect(<span class="number">1</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">6</span><span class="operator">,</span> <span class="number">4</span>);

</pre>
</td><td ><pre class="cpp">

  <span class="type"><a href="qpainter.html">QPainter</a></span> painter(<span class="keyword">this</span>);

  painter<span class="operator">.</span>setPen(<span class="type"><a href="qt-sub-qtgui.html">Qt</a></span><span class="operator">::</span>darkGreen);
  painter<span class="operator">.</span>drawLine(<span class="number">2</span><span class="operator">,</span> <span class="number">7</span><span class="operator">,</span> <span class="number">6</span><span class="operator">,</span> <span class="number">1</span>);

</pre>
</td></tr>
</table></div>
<p>When rendering with a pen with an even number of pixels, the pixels will be rendered symetrically around the mathematical defined points, while rendering with a pen with an odd number of pixels, the spare pixel will be rendered to the right and below the mathematical point as in the one pixel case. See the <a href="../qtcore/qrectf.html">QRectF</a> diagrams below for concrete examples.</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th  colspan="3"><a href="../qtcore/qrectf.html">QRectF</a></th></tr></thead>
<tr valign="top" class="odd"><td ><img src="images/qrect-diagram-zero.png" alt="" /></td><td ><img src="images/qrectf-diagram-one.png" alt="" /></td></tr>
<tr valign="top" class="even"><td >Logical representation</td><td >One pixel wide pen</td></tr>
<tr valign="top" class="odd"><td ><img src="images/qrectf-diagram-two.png" alt="" /></td><td ><img src="images/qrectf-diagram-three.png" alt="" /></td></tr>
<tr valign="top" class="even"><td >Two pixel wide pen</td><td >Three pixel wide pen</td></tr>
</table></div>
<p>Note that for historical reasons the return value of the <a href="../qtcore/qrect.html#right">QRect::right</a>() and <a href="../qtcore/qrect.html#bottom">QRect::bottom</a>() functions deviate from the true bottom-right corner of the rectangle.</p>
<p><a href="../qtcore/qrect.html">QRect</a>'s <a href="../qtcore/qrect.html#right">right()</a> function returns <a href="../qtcore/qrect.html#left">left()</a> + <a href="../qtcore/qrect.html#width">width()</a> - 1 and the <a href="../qtcore/qrect.html#bottom">bottom()</a> function returns <a href="../qtcore/qrect.html#top">top()</a> + <a href="../qtcore/qrect.html#height">height()</a> - 1. The bottom-right green point in the diagrams shows the return coordinates of these functions.</p>
<p>We recommend that you simply use <a href="../qtcore/qrectf.html">QRectF</a> instead: The <a href="../qtcore/qrectf.html">QRectF</a> class defines a rectangle in the plane using floating point coordinates for accuracy (<a href="../qtcore/qrect.html">QRect</a> uses integer coordinates), and the <a href="../qtcore/qrectf.html#right">QRectF::right</a>() and <a href="../qtcore/qrectf.html#bottom">QRectF::bottom</a>() functions <i>do</i> return the true bottom-right corner.</p>
<p>Alternatively, using <a href="../qtcore/qrect.html">QRect</a>, apply <a href="../qtcore/qrect.html#x">x()</a> + <a href="../qtcore/qrect.html#width">width()</a> and <a href="../qtcore/qrect.html#y">y()</a> + <a href="../qtcore/qrect.html#height">height()</a> to find the bottom-right corner, and avoid the <a href="../qtcore/qrect.html#right">right()</a> and <a href="../qtcore/qrect.html#bottom">bottom()</a> functions.</p>
<a name="anti-aliased-painting"></a>
<h3 id="anti-aliased-painting">Anti-aliased Painting</h3>
<p>If you set <a href="qpainter.html">QPainter</a>'s <a href="qpainter.html#RenderHint-enum">anti-aliasing</a> render hint, the pixels will be rendered symetrically on both sides of the mathematically defined points:</p>
<div class="table"><table class="generic">
 <tr valign="top" class="odd"><td ><img src="images/coordinatesystem-rect-antialias.png" alt="" /></td><td ><img src="images/coordinatesystem-line-antialias.png" alt="" /></td></tr>
<tr valign="top" class="even"><td ><pre class="cpp">

  <span class="type"><a href="qpainter.html">QPainter</a></span> painter(<span class="keyword">this</span>);
  painter<span class="operator">.</span>setRenderHint(
      <span class="type"><a href="qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing);
  painter<span class="operator">.</span>setPen(<span class="type"><a href="qt-sub-qtgui.html">Qt</a></span><span class="operator">::</span>darkGreen);
  painter<span class="operator">.</span>drawRect(<span class="number">1</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">6</span><span class="operator">,</span> <span class="number">4</span>);

</pre>
</td><td ><pre class="cpp">

  <span class="type"><a href="qpainter.html">QPainter</a></span> painter(<span class="keyword">this</span>);
  painter<span class="operator">.</span>setRenderHint(
      <span class="type"><a href="qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing);
  painter<span class="operator">.</span>setPen(<span class="type"><a href="qt-sub-qtgui.html">Qt</a></span><span class="operator">::</span>darkGreen);
  painter<span class="operator">.</span>drawLine(<span class="number">2</span><span class="operator">,</span> <span class="number">7</span><span class="operator">,</span> <span class="number">6</span><span class="operator">,</span> <span class="number">1</span>);

</pre>
</td></tr>
</table></div>
<a name="transformations"></a>
<h2 id="transformations">Transformations</h2>
<p>By default, the <a href="qpainter.html">QPainter</a> operates on the associated device's own coordinate system, but it also has complete support for affine coordinate transformations.</p>
<p>You can scale the coordinate system by a given offset using the <a href="qpainter.html#scale">QPainter::scale</a>() function, you can rotate it clockwise using the <a href="qpainter.html#rotate">QPainter::rotate</a>() function and you can translate it (i.e&#x2e; adding a given offset to the points) using the <a href="qpainter.html#translate">QPainter::translate</a>() function.</p>
<div class="table"><table class="generic">
 <tr valign="top" class="odd"><td ><img src="images/qpainter-clock.png" alt="" /></td><td ><img src="images/qpainter-rotation.png" alt="" /></td><td ><img src="images/qpainter-scale.png" alt="" /></td><td ><img src="images/qpainter-translation.png" alt="" /></td></tr>
<tr valign="top" class="even"><td >nop</td><td ><a href="qpainter.html#rotate">rotate()</a></td><td ><a href="qpainter.html#scale">scale()</a></td><td ><a href="qpainter.html#translate">translate()</a></td></tr>
</table></div>
<p>You can also twist the coordinate system around the origin using the <a href="qpainter.html#shear">QPainter::shear</a>() function. All the transformation operations operate on <a href="qpainter.html">QPainter</a>'s transformation matrix that you can retrieve using the <a href="qpainter.html#worldTransform">QPainter::worldTransform</a>() function. A matrix transforms a point in the plane to another point.</p>
<p>If you need the same transformations over and over, you can also use <a href="qtransform.html">QTransform</a> objects and the <a href="qpainter.html#worldTransform">QPainter::worldTransform</a>() and <a href="qpainter.html#setWorldTransform">QPainter::setWorldTransform</a>() functions. You can at any time save the <a href="qpainter.html">QPainter</a>'s transformation matrix by calling the <a href="qpainter.html#save">QPainter::save</a>() function which saves the matrix on an internal stack. The <a href="qpainter.html#restore">QPainter::restore</a>() function pops it back.</p>
<p>One frequent need for the transformation matrix is when reusing the same drawing code on a variety of paint devices. Without transformations, the results are tightly bound to the resolution of the paint device. Printers have high resolution, e.g&#x2e; 600 dots per inch, whereas screens often have between 72 and 100 dots per inch.</p>
<div class="table"><table class="generic" width="100%">
 <thead><tr class="qt-style"><th  colspan="2">Analog Clock Example</th></tr></thead>
<tr valign="top" class="odd"><td ><img src="images/coordinatesystem-analogclock.png" alt="" /></td><td >The Analog Clock example shows how to draw the contents of a custom widget using <a href="qpainter.html">QPainter</a>'s transformation matrix.<p>We recommend compiling and running this example before you read any further. In particular, try resizing the window to different sizes.</p>
</td></tr>
<tr valign="top" class="even"><td  colspan="2"><pre class="cpp">

  <span class="type">void</span> AnalogClockWindow<span class="operator">::</span>render(<span class="type"><a href="qpainter.html">QPainter</a></span> <span class="operator">*</span>p)
  {
      <span class="keyword">static</span> <span class="keyword">const</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> hourHand<span class="operator">[</span><span class="number">3</span><span class="operator">]</span> <span class="operator">=</span> {
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">7</span><span class="operator">,</span> <span class="number">8</span>)<span class="operator">,</span>
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="operator">-</span><span class="number">7</span><span class="operator">,</span> <span class="number">8</span>)<span class="operator">,</span>
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="operator">-</span><span class="number">40</span>)
      };
      <span class="keyword">static</span> <span class="keyword">const</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> minuteHand<span class="operator">[</span><span class="number">3</span><span class="operator">]</span> <span class="operator">=</span> {
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">7</span><span class="operator">,</span> <span class="number">8</span>)<span class="operator">,</span>
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="operator">-</span><span class="number">7</span><span class="operator">,</span> <span class="number">8</span>)<span class="operator">,</span>
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="operator">-</span><span class="number">70</span>)
      };

      <span class="type"><a href="qcolor.html">QColor</a></span> hourColor(<span class="number">127</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">127</span>);
      <span class="type"><a href="qcolor.html">QColor</a></span> minuteColor(<span class="number">0</span><span class="operator">,</span> <span class="number">127</span><span class="operator">,</span> <span class="number">127</span><span class="operator">,</span> <span class="number">191</span>);

      p<span class="operator">-</span><span class="operator">&gt;</span>setRenderHint(<span class="type"><a href="qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing);
      p<span class="operator">-</span><span class="operator">&gt;</span>translate(width() <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span> height() <span class="operator">/</span> <span class="number">2</span>);

      <span class="type">int</span> side <span class="operator">=</span> <a href="../qtcore/qtglobal.html#qMin">qMin</a>(width()<span class="operator">,</span> height());
      p<span class="operator">-</span><span class="operator">&gt;</span>scale(side <span class="operator">/</span> <span class="number">200.0</span><span class="operator">,</span> side <span class="operator">/</span> <span class="number">200.0</span>);

</pre>
<p>We translate the coordinate system so that point (0, 0) is in the widget's center, instead of being at the top-left corner. We also scale the system by <code>side</code> / 100, where <code>side</code> is either the widget's width or the height, whichever is shortest. We want the clock to be square, even if the device isn't.</p>
<p>This will give us a 200 x 200 square area, with the origin (0, 0) in the center, that we can draw on. What we draw will show up in the largest possible square that will fit in the widget.</p>
<p>See also the <a href="coordsys.html#window-viewport-conversion">Window-Viewport Conversion</a> section.</p>
<pre class="cpp">

      <span class="type"><a href="../qtcore/qtime.html">QTime</a></span> time <span class="operator">=</span> <span class="type"><a href="../qtcore/qtime.html">QTime</a></span><span class="operator">::</span>currentTime();

      p<span class="operator">-</span><span class="operator">&gt;</span>save();
      p<span class="operator">-</span><span class="operator">&gt;</span>rotate(<span class="number">30.0</span> <span class="operator">*</span> ((time<span class="operator">.</span>hour() <span class="operator">+</span> time<span class="operator">.</span>minute() <span class="operator">/</span> <span class="number">60.0</span>)));
      p<span class="operator">-</span><span class="operator">&gt;</span>drawConvexPolygon(hourHand<span class="operator">,</span> <span class="number">3</span>);
      p<span class="operator">-</span><span class="operator">&gt;</span>restore();

</pre>
<p>We draw the clock's hour hand by rotating the coordinate system and calling <a href="qpainter.html#drawConvexPolygon">QPainter::drawConvexPolygon</a>(). Thank's to the rotation, it's drawn pointed in the right direction.</p>
<p>The polygon is specified as an array of alternating <i>x</i>, <i>y</i> values, stored in the <code>hourHand</code> static variable (defined at the beginning of the function), which corresponds to the four points (2, 0), (0, 2), (-2, 0), and (0, -25).</p>
<p>The calls to <a href="qpainter.html#save">QPainter::save</a>() and <a href="qpainter.html#restore">QPainter::restore</a>() surrounding the code guarantees that the code that follows won't be disturbed by the transformations we've used.</p>
<pre class="cpp">

      p<span class="operator">-</span><span class="operator">&gt;</span>save();
      p<span class="operator">-</span><span class="operator">&gt;</span>rotate(<span class="number">6.0</span> <span class="operator">*</span> (time<span class="operator">.</span>minute() <span class="operator">+</span> time<span class="operator">.</span>second() <span class="operator">/</span> <span class="number">60.0</span>));
      p<span class="operator">-</span><span class="operator">&gt;</span>drawConvexPolygon(minuteHand<span class="operator">,</span> <span class="number">3</span>);
      p<span class="operator">-</span><span class="operator">&gt;</span>restore();

</pre>
<p>We do the same for the clock's minute hand, which is defined by the four points (1, 0), (0, 1), (-1, 0), and (0, -40). These coordinates specify a hand that is thinner and longer than the minute hand.</p>
<pre class="cpp">

      p<span class="operator">-</span><span class="operator">&gt;</span>setPen(minuteColor);

      <span class="keyword">for</span> (<span class="type">int</span> j <span class="operator">=</span> <span class="number">0</span>; j <span class="operator">&lt;</span> <span class="number">60</span>; <span class="operator">+</span><span class="operator">+</span>j) {
          <span class="keyword">if</span> ((j <span class="operator">%</span> <span class="number">5</span>) <span class="operator">!</span><span class="operator">=</span> <span class="number">0</span>)
              p<span class="operator">-</span><span class="operator">&gt;</span>drawLine(<span class="number">92</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">96</span><span class="operator">,</span> <span class="number">0</span>);
          p<span class="operator">-</span><span class="operator">&gt;</span>rotate(<span class="number">6.0</span>);
      }

</pre>
<p>Finally, we draw the clock face, which consists of twelve short lines at 30-degree intervals. At the end of that, the painter is rotated in a way which isn't very useful, but we're done with painting so that doesn't matter.</p>
</td></tr>
</table></div>
<p>For more information about the transformation matrix, see the <a href="qtransform.html">QTransform</a> documentation.</p>
<a name="window-viewport-conversion"></a>
<h2 id="window-viewport-conversion">Window-Viewport Conversion</h2>
<p>When drawing with <a href="qpainter.html">QPainter</a>, we specify points using logical coordinates which then are converted into the physical coordinates of the paint device.</p>
<p>The mapping of the logical coordinates to the physical coordinates are handled by <a href="qpainter.html">QPainter</a>'s world transformation <a href="qpainter.html#worldTransform">worldTransform()</a> (described in the <a href="coordsys.html#transformations">Transformations</a> section), and <a href="qpainter.html">QPainter</a>'s <a href="qpainter.html#viewport">viewport()</a> and <a href="qpainter.html#window">window()</a>. The viewport represents the physical coordinates specifying an arbitrary rectangle. The &quot;window&quot; describes the same rectangle in logical coordinates. By default the logical and physical coordinate systems coincide, and are equivalent to the paint device's rectangle.</p>
<p>Using window-viewport conversion you can make the logical coordinate system fit your preferences. The mechanism can also be used to make the drawing code independent of the paint device. You can, for example, make the logical coordinates extend from (-50, -50) to (50, 50) with (0, 0) in the center by calling the <a href="qpainter.html#setWindow">QPainter::setWindow</a>() function:</p>
<pre class="cpp">

  <span class="type"><a href="qpainter.html">QPainter</a></span> painter(<span class="keyword">this</span>);
  painter<span class="operator">.</span>setWindow(<span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(<span class="operator">-</span><span class="number">50</span><span class="operator">,</span> <span class="operator">-</span><span class="number">50</span><span class="operator">,</span> <span class="number">100</span><span class="operator">,</span> <span class="number">100</span>));

</pre>
<p>Now, the logical coordinates (-50,-50) correspond to the paint device's physical coordinates (0, 0). Independent of the paint device, your painting code will always operate on the specified logical coordinates.</p>
<p>By setting the &quot;window&quot; or viewport rectangle, you perform a linear transformation of the coordinates. Note that each corner of the &quot;window&quot; maps to the corresponding corner of the viewport, and vice versa. For that reason it normally is a good idea to let the viewport and &quot;window&quot; maintain the same aspect ratio to prevent deformation:</p>
<pre class="cpp">

  <span class="type">int</span> side <span class="operator">=</span> <a href="../qtcore/qtglobal.html#qMin">qMin</a>(width()<span class="operator">,</span> height())
  <span class="type">int</span> x <span class="operator">=</span> (width() <span class="operator">-</span> side <span class="operator">/</span> <span class="number">2</span>);
  <span class="type">int</span> y <span class="operator">=</span> (height() <span class="operator">-</span> side <span class="operator">/</span> <span class="number">2</span>);

  painter<span class="operator">.</span>setViewport(x<span class="operator">,</span> y<span class="operator">,</span> side<span class="operator">,</span> side);

</pre>
<p>If we make the logical coordinate system a square, we should also make the viewport a square using the <a href="qpainter.html#setViewport">QPainter::setViewport</a>() function. In the example above we make it equivalent to the largest square that fit into the paint device's rectangle. By taking the paint device's size into consideration when setting the window or viewport, it is possible to keep the drawing code independent of the paint device.</p>
<p>Note that the window-viewport conversion is only a linear transformation, i.e&#x2e; it does not perform clipping. This means that if you paint outside the currently set &quot;window&quot;, your painting is still transformed to the viewport using the same linear algebraic approach.</p>
<p class="centerAlign"><img src="images/coordinatesystem-transformations.png" alt="" /></p><p>The viewport, &quot;window&quot; and transformation matrix determine how logical <a href="qpainter.html">QPainter</a> coordinates map to the paint device's physical coordinates. By default the world transformation matrix is the identity matrix, and the &quot;window&quot; and viewport settings are equivalent to the paint device's settings, i.e&#x2e; the world, &quot;window&quot; and device coordinate systems are equivalent, but as we have seen, the systems can be manipulated using transformation operations and window-viewport conversion. The illustration above describes the process.</p>
</div>
<p><b>See also </b><a href="qtgui-analogclock-example.html">Analog Clock Window Example</a>.</p>
<!-- @@@coordsys.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>