1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - QPixmap Class</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center>QPixmap Class Reference</h1><br clear="all">
<p>
The QPixmap class is an off-screen pixel-based paint device.
<a href="#details">More...</a>
<p>
<code>#include <<a href="qpixmap-h.html">qpixmap.h</a>></code>
<p>
Inherits <a href="qpaintdevice.html">QPaintDevice</a> and <a href="qt.html">Qt</a>.
<p>Inherited by <a href="qbitmap.html">QBitmap</a> and <a href="qcanvaspixmap.html">QCanvasPixmap</a>.
<p><a href="qpixmap-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class="fn">enum<a href="#ColorMode"><b>ColorMode</b></a>{Auto, Color, Mono}</div>
<li><div class="fn">enum<a href="#Optimization"><b>Optimization</b></a>{DefaultOptim, NoOptim, MemoryOptim=NoOptim, NormalOptim, BestOptim}</div>
<li><div class="fn"><a href="#0b95b1"><b>QPixmap</b></a>()</div>
<li><div class="fn"><a href="#d66eb9"><b>QPixmap</b></a>(intw, inth, intdepth=-1, Optimization=DefaultOptim)</div>
<li><div class="fn"><a href="#c06940"><b>QPixmap</b></a>(constQSize&, intdepth=-1, Optimization=DefaultOptim)</div>
<li><div class="fn"><a href="#5b3798"><b>QPixmap</b></a>(constQString&fileName, constchar*format=0, ColorModemode=Auto)</div>
<li><div class="fn"><a href="#2cf92e"><b>QPixmap</b></a>(constQString&fileName, constchar*format, intconversion_flags)</div>
<li><div class="fn"><a href="#6f4934"><b>QPixmap</b></a>(constchar*xpm[])</div>
<li><div class="fn"><a href="#cfb2d6"><b>QPixmap</b></a>(constQByteArray&data)</div>
<li><div class="fn"><a href="#6840fd"><b>QPixmap</b></a>(constQPixmap&)</div>
<li><div class="fn"><a href="#d8dcf1"><b>~QPixmap</b></a>()</div>
<li><div class="fn">QPixmap&<a href="#4a19b0"><b>operator=</b></a>(constQPixmap&)</div>
<li><div class="fn">QPixmap&<a href="#f29bf5"><b>operator=</b></a>(constQImage&)</div>
<li><div class="fn">bool<a href="#7803c4"><b>isNull</b></a>()const</div>
<li><div class="fn">int<a href="#86dbc5"><b>width</b></a>()const</div>
<li><div class="fn">int<a href="#d5bb33"><b>height</b></a>()const</div>
<li><div class="fn">QSize<a href="#60b65f"><b>size</b></a>()const</div>
<li><div class="fn">QRect<a href="#fbdfe3"><b>rect</b></a>()const</div>
<li><div class="fn">int<a href="#3c91c2"><b>depth</b></a>()const</div>
<li><div class="fn">void<a href="#6910a0"><b>fill</b></a>(constQColor&fillColor=Qt::white)</div>
<li><div class="fn">void<a href="#aca980"><b>fill</b></a>(constQWidget*, intxofs, intyofs)</div>
<li><div class="fn">void<a href="#9167e5"><b>fill</b></a>(constQWidget*, constQPoint&ofs)</div>
<li><div class="fn">void<a href="#b4f156"><b>resize</b></a>(intwidth, intheight)</div>
<li><div class="fn">void<a href="#360eec"><b>resize</b></a>(constQSize&)</div>
<li><div class="fn">constQBitmap*<a href="#99119c"><b>mask</b></a>()const</div>
<li><div class="fn">void<a href="#68a75d"><b>setMask</b></a>(constQBitmap&)</div>
<li><div class="fn">bool<a href="#848613"><b>selfMask</b></a>()const</div>
<li><div class="fn">QBitmap<a href="#20dfb1"><b>createHeuristicMask</b></a>(boolclipTight=TRUE)const</div>
<li><div class="fn">QPixmap<a href="#ff5fcf"><b>xForm</b></a>(constQWMatrix&)const</div>
<li><div class="fn">QImage<a href="#8c5f15"><b>convertToImage</b></a>()const</div>
<li><div class="fn">bool<a href="#b6a662"><b>convertFromImage</b></a>(constQImage&, ColorModemode=Auto)</div>
<li><div class="fn">bool<a href="#00951a"><b>convertFromImage</b></a>(constQImage&, intconversion_flags)</div>
<li><div class="fn">bool<a href="#bdbe68"><b>load</b></a>(constQString&fileName, constchar*format=0, ColorModemode=Auto)</div>
<li><div class="fn">bool<a href="#a728cf"><b>load</b></a>(constQString&fileName, constchar*format, intconversion_flags)</div>
<li><div class="fn">bool<a href="#32699f"><b>loadFromData</b></a>(constuchar*buf, uintlen, constchar*format=0, ColorModemode=Auto)</div>
<li><div class="fn">bool<a href="#79475e"><b>loadFromData</b></a>(constuchar*buf, uintlen, constchar*format, intconversion_flags)</div>
<li><div class="fn">bool<a href="#b0e017"><b>loadFromData</b></a>(constQByteArray&data, constchar*format=0, intconversion_flags=0)</div>
<li><div class="fn">bool<a href="#e02a5b"><b>save</b></a>(constQString&fileName, constchar*format)const</div>
<li><div class="fn">bool<a href="#a38b1c"><b>save</b></a>(constQString&fileName, constchar*format, intquality)const</div>
<li><div class="fn">int<a href="#4f47d9"><b>serialNumber</b></a>()const</div>
<li><div class="fn">Optimization<a href="#ae6199"><b>optimization</b></a>()const</div>
<li><div class="fn">void<a href="#41f5cf"><b>setOptimization</b></a>(Optimization)</div>
<li><div class="fn">virtualvoid<a href="#81b941"><b>detach</b></a>()</div>
<li><div class="fn">bool<a href="#c0b272"><b>isQBitmap</b></a>()const</div>
</ul>
<h2>Static Public Members</h2>
<ul>
<li><div class="fn">int<a href="#e194ad"><b>defaultDepth</b></a>()</div>
<li><div class="fn">QPixmap<a href="#a7861f"><b>grabWindow</b></a>(WId, intx=0, inty=0, intw=-1, inth=-1)</div>
<li><div class="fn">QPixmap<a href="#e492b7"><b>grabWidget</b></a>(QWidget*widget, intx=0, inty=0, intw=-1, inth=-1)</div>
<li><div class="fn">QWMatrix<a href="#952384"><b>trueMatrix</b></a>(constQWMatrix&, intw, inth)</div>
<li><div class="fn">constchar*<a href="#360626"><b>imageFormat</b></a>(constQString&fileName)</div>
<li><div class="fn">Optimization<a href="#3ad81f"><b>defaultOptimization</b></a>()</div>
<li><div class="fn">void<a href="#7675b8"><b>setDefaultOptimization</b></a>(Optimization)</div>
</ul>
<h2>Protected Members</h2>
<ul>
<li><div class="fn"><a href="#998315"><b>QPixmap</b></a>(intw, inth, constuchar*data, boolisXbitmap)</div>
<li><div class="fn">virtualint<a href="#fa32cf"><b>metric</b></a>(int)const</div>
</ul>
<h2>Related Functions</h2>
(Note that these are not member functions.)
<ul>
<li>QDataStream & <a href="qpixmap.html#3d1a55"><b>operator>></b></a> (QDataStream & s, QPixmap & pixmap)
<li>QDataStream & <a href="qpixmap.html#6958b6"><b>operator<<</b></a> (QDataStream & s, const QPixmap & pixmap)
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QPixmap class is an off-screen pixel-based paint device.
<p>
It is one of the two classes Qt provides for dealing with images,
the other being <a href="qimage.html">QImage</a>. QPixmap is designed and optimized for
drawing; QImage is designed and optimized for I/O and for direct
pixel access/manipulation. There are (slow) functions to convert
between QImage and QPixmap; <a href="#8c5f15">convertToImage</a>() and <a href="#00951a">convertFromImage</a>().
<p>One common use of the QPixmap class is to enable smooth updating of
widgets. Whenever something complex needs to be drawn, you can use
a pixmap to obtain flicker-free drawing, like this:
<p><ol plain>
<li> Create a pixmap with the same size as the widget.
<li> Fill the pixmap with the widget background color.
<li> Paint the pixmap.
<li> <a href="qpaintdevice.html#35ae2e">bitBlt</a>() the pixmap contents onto the widget.
</ol>
<p>Pixel data in a pixmap is internal and managed by the underlying
window system. Pixels can only be accessed through <a href="qpainter.html">QPainter</a>
functions, through bitBlt(), and by converting the QPixmap to a
QImage.
<p>You can display a QPixmap on the screen easily using
e.g. <a href="qlabel.html#4acf9b">QLabel::setPixmap</a>(), and all the <a href="qbutton.html">QButton</a> subclasses support
pixmap use.
<p>The QPixmap class uses lazy copying, so it is practical to pass pass
QPixmap objects as arguments.
<p>Note about Windows 95 and 98: On Windows 9x, the system crashes if
you create more than approximately 1000 pixmaps, independent of the
size of the pixmaps or installed RAM. Windows NT does not have this
limitation.
<p>Qt tries to work around the resource limitation. If you set the
pixmap optimization to <code>QPixmap::MemoryOptim</code> and the width of your
pixmap is less than or equal to 128 pixels, Qt stores the pixmap in
a way which is very memory-efficient when there are many pixmaps.
<p>If your application uses dozens or hundreds of pixmaps, e.g. on tool
bar buttons, in popup menus, and you plan to run it on Windows 95 or
Windows 98, then we recommend using code like this:
<p><pre> <a href="#7675b8">QPixmap::setDefaultOptimization</a>( QPixmap::MemoryOptim );
while ( ... ) {
// load tool bar pixmaps etc.
<a href="qpixmap.html">QPixmap</a> *pixmap = new <a href="qpixmap.html">QPixmap</a>(fileName);
}
<a href="#7675b8">QPixmap::setDefaultOptimization</a>( QPixmap::NormalOptim );
</pre>
<p>See also <a href="qbitmap.html">QBitmap</a>, <a href="qimage.html">QImage</a>, <a href="qimageio.html">QImageIO</a> and <a href="shclass.html">Shared Classes</a>
<p>Examples:
<a href="qtimage-qtimage-cpp.html#QPixmap">qtimage/qtimage.cpp</a>
<a href="xform-xform-cpp.html#QPixmap">xform/xform.cpp</a>
<a href="menu-menu-cpp.html#QPixmap">menu/menu.cpp</a>
<a href="qmag-qmag-cpp.html#QPixmap">qmag/qmag.cpp</a>
<a href="desktop-desktop-cpp.html#QPixmap">desktop/desktop.cpp</a>
<a href="scrollview-scrollview-cpp.html#QPixmap">scrollview/scrollview.cpp</a>
<a href="movies-main-cpp.html#QPixmap">movies/main.cpp</a>
<a href="picture-picture-cpp.html#QPixmap">picture/picture.cpp</a>
<hr><h2>Member Type Documentation</h2>
<h3 class="fn"><a name="ColorMode">QPixmap::ColorMode</a></h3>
This enum type defines the color modes that exist for converting
<a href="qimage.html">QImage</a> objects to QPixmap. The current values are: <ul>
<li> <code>Auto</code> - select <code>Color</code> or <code>Mono</code> on a case-by-case basis.
<li> <code>Color</code> - always create colored pixmaps.
<li> <code>Mono</code> - always create bitmaps.
</ul>
<h3 class="fn"><a name="Optimization">QPixmap::Optimization</a></h3>
QPixmap has the choice of optimizing for speed or memory in a few
places, and the best choice varies from pixmap to pixmap, but can
generally be derived heuristically. This enum type defines a number
of optimization modes you can set for any pixmap, to tweak the
speed/memory tradeoffs:
<p><ul>
<li> <code>DefaultOptim</code> - whatever <a href="#3ad81f">QPixmap::defaultOptimization</a>()
returns. A pixmap with this optimization mode set always has the
default optimization type, even if the default is changed with
<a href="#7675b8">setDefaultOptimization</a>().
<li> <code>NoOptim</code> - no optimization (currently the same as <code>MemoryOptim).</code>
<li> <code>MemoryOptim</code> - optimize for minimal memory use.
<li> <code>NormalOptim</code> - optimize for typical usage. Often uses more
memory than <code>MemoryOptim,</code> and often faster.
<li> <code>BestOptim</code> - optimize for pixmaps that are drawn very often
and where performance is critical. Generally uses more memory than
<code>NormalOptim</code> and may provide a little better speed.
<p></ul>
<p>We recommend sticking with <code>DefaultOptim</code>
<hr><h2>Member Function Documentation</h2>
<h3 class="fn"><a name="0b95b1"></a>QPixmap::QPixmap()</h3>
<p>Constructs a null pixmap.
<p>See also <a href="#7803c4">isNull</a>().
<h3 class="fn"><a name="cfb2d6"></a>QPixmap::QPixmap(const<a href="qbytearray.html">QByteArray</a>&img_data)</h3>
<p>Constructs a pixmaps by loading from <em>img_data.</em>
The data can be in any image format supported by Qt.
<p>See also <a href="#79475e">loadFromData</a>().
<h3 class="fn"><a name="2cf92e"></a>QPixmap::QPixmap(const<a href="qstring.html">QString</a>&fileName, constchar*format, intconversion_flags)</h3>
<p>Constructs a pixmap from the file <em>fileName.</em> If the file does not
exist, or is of an unknown format, the pixmap becomes a null pixmap.
<p>The parameters are passed on to <a href="#a728cf">load</a>().
<p>See also <a href="#7803c4">isNull</a>(), <a href="#a728cf">load</a>(), <a href="#79475e">loadFromData</a>(), <a href="#a38b1c">save</a>() and <a href="#360626">imageFormat</a>().
<h3 class="fn"><a name="5b3798"></a>QPixmap::QPixmap(const<a href="qstring.html">QString</a>&fileName, constchar*format=0, <a href="qpixmap.html#ColorMode">ColorMode</a>mode=Auto)</h3>
<p>Constructs a pixmap from the file <em>fileName.</em> If the file does not
exist, or is of an unknown format, the pixmap becomes a null pixmap.
<p>The parameters are passed on to <a href="#a728cf">load</a>().
<p>See also <a href="#7803c4">isNull</a>(), <a href="#a728cf">load</a>(), <a href="#79475e">loadFromData</a>(), <a href="#a38b1c">save</a>() and <a href="#360626">imageFormat</a>().
<h3 class="fn"><a name="6840fd"></a>QPixmap::QPixmap(constQPixmap&pixmap)</h3>
<p>Constructs a pixmap which is a copy of <em>pixmap.</em>
<h3 class="fn"><a name="6f4934"></a>QPixmap::QPixmap(constchar*xpm[])</h3>
<p>Constructs a pixmap from <em>xpm,</em> which must be a valid XPM image.
<p>Error are silently ignored.
<p>Note that it's possible to squeeze the XPM variable a little bit by
using an unusual declaration:
<p><pre> static const char * const start_xpm[]={
"16 15 8 1",
"a c #cec6bd",
....
</pre>
<p>The extra <code>const</code> makes the entire definition read-only, which is
slightly more efficient e.g. when the code is in a shared library,
and ROMable when the application is to be stored in ROM.
<p>In order to use that sort of declaration, you must cast the variable
back to <nobr><code>const char **</code></nobr> when you create the
QPixmap.
<h3 class="fn"><a name="998315"></a>QPixmap::QPixmap(intw, inth, constuchar*bits, boolisXbitmap) <code>[protected]</code></h3>
<p>Constructs a monochrome pixmap which is initialized with the data in <em>bits.</em>
This constructor is protected and used by the <a href="qbitmap.html">QBitmap</a> class.
<h3 class="fn"><a name="d66eb9"></a>QPixmap::QPixmap(intw, inth, intdepth=-1, <a href="qpixmap.html#Optimization">Optimization</a>optimization=DefaultOptim)</h3>
<p>Constructs a pixmap with <em>w</em> width, <em>h</em> height and of <em>depth</em> bits per
pixels.
<p>The contents of the pixmap is uninitialized.
<p>The <em>depth</em> can be either 1 (monochrome) or the depth of the
current video mode. If <em>depth</em> is negative, then the hardware
depth of the current video mode will be used.
<p>If either <em>width</em> or <em>height</em> is zero, a null pixmap is constructed.
<p>See also <a href="#7803c4">isNull</a>().
<h3 class="fn"><a name="c06940"></a>QPixmap::QPixmap(const<a href="qsize.html">QSize</a>&size, intdepth=-1, <a href="qpixmap.html#Optimization">Optimization</a>optimization=DefaultOptim)</h3>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<h3 class="fn"><a name="d8dcf1"></a>QPixmap::~QPixmap()</h3>
<p>Destructs the pixmap.
<h3 class="fn">bool<a name="00951a"></a>QPixmap::convertFromImage(const<a href="qimage.html">QImage</a>&img, intconversion_flags)</h3>
<p>Converts an image and sets this pixmap. Returns TRUE if successful.
<p>The <em>conversion_flags</em> argument is a bitwise-OR from the following choices.
The options marked <em>(default)</em> are the choice if no other choice from the
list is included (they are zero):
<p><dl>
<dt>Color/Mono preference (ignored for <a href="qbitmap.html">QBitmap</a>)
<dd>
<ul>
<li> <code>AutoColor</code> (default) - If the <em>image</em> has <a href="qimage.html#682415">depth</a> 1 and contains only
black and white pixels, then the pixmap becomes monochrome.
<li> <code>ColorOnly</code> - The pixmap is dithered/converted to the
<a href="#e194ad">native display depth</a>.
<li> <code>MonoOnly</code> - The pixmap becomes monochrome. If necessary,
it is dithered using the chosen dithering algorithm.
</ul>
<dt>Dithering mode preference, for RGB channels
<dd>
<ul>
<li> <code>DiffuseDither</code> (default) - a high quality dither
<li> <code>OrderedDither</code> - a faster more ordered dither
<li> <code>ThresholdDither</code> - no dithering, closest color is used
</ul>
<dt>Dithering mode preference, for alpha channel
<dd>
<ul>
<li> <code>DiffuseAlphaDither</code> - a high quality dither
<li> <code>OrderedAlphaDither</code> - a faster more ordered dither
<li> <code>ThresholdAlphaDither</code> (default) - no dithering
</ul>
<dt>Color matching versus dithering preference
<dd>
<ul>
<li> <code>PreferDither</code> - always dither 32-bit images when
the image
is being converted to 8-bits.
This is the default when converting to a pixmap.
<li> <code>AvoidDither</code> - only dither 32-bit images if
the image
has more than 256 colors and it
is being converted to 8-bits.
This is the default when an image is converted
for the purpose of saving to a file.
</ul>
</dl>
<p>Passing 0 for <em>conversion_flags</em> gives all the default options.
<p>Note that even though a QPixmap with depth 1 behaves much like a
QBitmap, <a href="#c0b272">isQBitmap</a>() returns FALSE.
<p>If a pixmap with depth 1 is painted with color0 and color1 and
converted to an image, the pixels painted with color0 will produce
pixel index 0 in the image and those painted with color1 will produce
pixel index 1.
<p>See also <a href="#8c5f15">convertToImage</a>(), <a href="#c0b272">isQBitmap</a>(), <a href="qimage.html#ffa6d1">QImage::convertDepth</a>(), <a href="#e194ad">defaultDepth</a>() and <a href="qimage.html#327d97">QImage::hasAlphaBuffer</a>().
<p>Bugs and limitations:
<ul>
<li>Does not support 2 or 4 bit display hardware.
</ul>
<p>Examples:
<a href="qtimage-qtimage-cpp.html#convertFromImage">qtimage/qtimage.cpp</a>
<h3 class="fn">bool<a name="b6a662"></a>QPixmap::convertFromImage(const<a href="qimage.html">QImage</a>&image, <a href="qpixmap.html#ColorMode">ColorMode</a>mode=Auto)</h3>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<h3 class="fn"><a href="qimage.html">QImage</a><a name="8c5f15"></a>QPixmap::convertToImage()const</h3>
<p>Converts the pixmap to an image. Returns a null image if the operation
failed.
<p>If the pixmap has 1 bit depth, the returned image will also be 1
bits deep. If the pixmap has 2-8 bit depth, the returned image
has 8 bit depth. If the pixmap has greater than 8 bit depth, the
returned image has 32 bit depth.
<p>See also <a href="#00951a">convertFromImage</a>().
<p>Bugs and limitations:
<ul>
<li>Does not support 2 or 4 bit display hardware.
<li>Alpha masks on monochrome images are ignored.
</ul>
<p>Examples:
<a href="qmag-qmag-cpp.html#convertToImage">qmag/qmag.cpp</a>
<h3 class="fn"><a href="qbitmap.html">QBitmap</a><a name="20dfb1"></a>QPixmap::createHeuristicMask(boolclipTight=TRUE)const</h3>
<p>Creates and returns a heuristic mask for this pixmap. It works by
selecting a color from one of the corners, then chipping away pixels of
that color, starting at all the edges.
<p>The mask may not be perfect but should be reasonable, so you can do
things like:
<pre> pm->setMask( pm->createHeuristicMask() );
</pre>
<p>This function is slow because it involves transformation to a <a href="qimage.html">QImage</a>,
non-trivial computations and a transformation back to <a href="qbitmap.html">QBitmap</a>.
<p>See also <a href="qimage.html#582c18">QImage::createHeuristicMask</a>().
<h3 class="fn">int<a name="e194ad"></a>QPixmap::defaultDepth() <code>[static]</code></h3>
<p>Returns the default pixmap depth, i.e. the depth a pixmap gets
if -1 is specified.
<p>See also <a href="#3c91c2">depth</a>().
<h3 class="fn">QPixmap::Optimization<a name="3ad81f"></a>QPixmap::defaultOptimization() <code>[static]</code></h3>
<p>Returns the default pixmap optimization setting.
<p>See also <a href="#7675b8">setDefaultOptimization</a>(), <a href="#41f5cf">setOptimization</a>() and <a href="#ae6199">optimization</a>().
<h3 class="fn">int<a name="3c91c2"></a>QPixmap::depth()const</h3>
<p>Returns the depth of the image.
<p>The pixmap depth is also called bits per pixel (bpp) or bit planes
of a pixmap. A null pixmap has depth 0.
<p>See also <a href="#e194ad">defaultDepth</a>(), <a href="#7803c4">isNull</a>() and <a href="qimage.html#ffa6d1">QImage::convertDepth</a>().
<h3 class="fn">void<a name="81b941"></a>QPixmap::detach() <code>[virtual]</code></h3>
<p>Special-purpose function that detaches the pixmap from shared pixmap data.
<p>A pixmap is automatically detached by Qt whenever its contents is about
to change. This is done in all QPixmap member functions that modify the
pixmap (<a href="#6910a0">fill</a>(), <a href="#b4f156">resize</a>(), <a href="#00951a">convertFromImage</a>(), <a href="#a728cf">load</a>() etc.), in <a href="qpaintdevice.html#35ae2e">bitBlt</a>()
for the destination pixmap and in <a href="qpainter.html#02ed5d">QPainter::begin</a>() on a pixmap.
<p>It is possible to modify a pixmap without letting Qt know.
You can first obtain the <a href="qpaintdevice.html#1f2053">system-dependent handle</a>
and then call system-specific functions (for instance BitBlt under Windows)
that modifies the pixmap contents. In this case, you can call detach()
to cut the pixmap loose from other pixmaps that share data with this one.
<p>detach() returns immediately if there is just a single reference or if
the pixmap has not been initialized yet.
<h3 class="fn">void<a name="6910a0"></a>QPixmap::fill(const<a href="qcolor.html">QColor</a>&fillColor=Qt::white)</h3>
<p>Fills the pixmap with the color <em>fillColor.</em>
<p>Examples:
<a href="xform-xform-cpp.html#fill">xform/xform.cpp</a>
<a href="desktop-desktop-cpp.html#fill">desktop/desktop.cpp</a>
<h3 class="fn">void<a name="9167e5"></a>QPixmap::fill(const<a href="qwidget.html">QWidget</a>*widget, const<a href="qpoint.html">QPoint</a>&ofs)</h3>
<p>Fills the pixmap with the widget's background color or pixmap.
If the background is empty, nothing is done.
<p>The <em>ofs</em> point is an offset in the widget.
<p>The point <em>ofs</em> is a point in the widget's coordinate system. The
pixmap's top left pixel will be mapped to the point <em>ofs</em> in the
widget. This is significant if the widget has a background pixmap,
otherwise the pixmap will simply be filled with the background color of
the widget.
<p>Example:
<pre> void CuteWidget::paintEvent( <a href="qpaintevent.html">QPaintEvent</a> *e )
{
<a href="qrect.html">QRect</a> ur = e-><a href="qpaintevent.html#2d6e18">rect</a>(); // rectangle to update
<a href="qpixmap.html">QPixmap</a> pix( ur.<a href="qrect.html#507cd9">size</a>() ); // Pixmap for double-buffering
pix.<a href="#6910a0">fill</a>( this, ur.<a href="qrect.html#349186">topLeft</a>() ); // fill with widget background
<a href="qpainter.html">QPainter</a> p( &pix );
p.<a href="qpainter.html#eb778c">translate</a>( -ur.<a href="qrect.html#fccae7">x</a>(), -ur.<a href="qrect.html#f448f7">y</a>() ); // use widget coordinate system
// when drawing on pixmap
// ... draw on pixmap ...
p.<a href="qpainter.html#365784">end</a>();
<a href="qpaintdevice.html#35ae2e">bitBlt</a>( this, ur.<a href="qrect.html#349186">topLeft</a>(), &pix );
}
</pre>
<h3 class="fn">void<a name="aca980"></a>QPixmap::fill(const<a href="qwidget.html">QWidget</a>*widget, intxofs, intyofs)</h3>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<h3 class="fn">QPixmap<a name="e492b7"></a>QPixmap::grabWidget(<a href="qwidget.html">QWidget</a>*widget, intx=0, inty=0, intw=-1, inth=-1) <code>[static]</code></h3>
<p>Creates a pixmap and paints <em>widget</em> in it.
<p>If <em>widget</em> has children, they are painted too, appropriately located.
<p>If you specify <em>x, y, w</em> or <em>h,</em> only the rectangle you
specify is painted. The defaults are 0, 0 (top-left corner) and
-1,-1 (which means the entire widget).
<p>(If <em>w</em> is negative, the function copies everything to the right
border of the window. If <em>h</em> is negative, the function copies
everything to the bottom of the window.)
<p>If <em>widget</em> is 0, or if the rectangle defined by <em>x, y,</em> the
modified <em>w</em> and the modified <em>h</em> does not overlap the <em>widget-><a href="#fbdfe3">rect</a>(),</em> this function returns a null QPixmap.
<p>This function actually asks <em>widget</em> to paint itself (and its
children to paint themselves). <a href="#a7861f">QPixmap::grabWindow</a>() grabs pixels
off the screen, which is a bit faster and picks up <em>exactly</em> what's
on-screen. This function works by calling paintEvent() with painter
redirection turned on, which gets the result of paintEvent(),
without e.g. overlying windows.
<p>If there is overlap, it returns a pixmap of the size you want,
containing a rendering of <em>widget.</em> If the rectangle you ask for
is a superset of <em>widget,</em> the area outside <em>widget</em> are covered
with the widget's background.
<p>See also <a href="#a7861f">grabWindow</a>(), <a href="qpainter.html#ab2ec8">QPainter::redirect</a>() and <a href="qwidget.html#e3d821">QWidget::paintEvent</a>().
<h3 class="fn">QPixmap<a name="a7861f"></a>QPixmap::grabWindow(WIdwindow, intx=0, inty=0, intw=-1, inth=-1) <code>[static]</code></h3>
<p>Grabs the contents of a window and makes a pixmap out of it.
Returns the pixmap.
<p>The arguments <em>(x,y)</em> specify the offset in the window, while
<em>(w,h)</em> specify the width and height of the area to be copied.
<p>If <em>w</em> is negative, the function copies everything to the right
border of the window. If <em>h</em> is negative, the function copies
everything to the bottom of the window.
<p>Note that grabWindows() grabs pixels from the screen, not from the
window. This means that If there is another window partially or
entirely over the one you grab, you get pixels from the overlying
window too.
<p>Note also that the mouse cursor is generally not grabbed.
<p>The reason we use a window identifier and not a <a href="qwidget.html">QWidget</a> is to enable
grabbing of windows that are not part of the application, window
system frames, and so on.<p><b>Warning:</b> Grabbing an area outside the screen is not safe in general.
This depends on the underlying window system.
<p>See also <a href="#e492b7">grabWidget</a>().
<h3 class="fn">int<a name="d5bb33"></a>QPixmap::height()const</h3>
<p>Returns the height of the pixmap.
<p>See also <a href="#86dbc5">width</a>(), <a href="#60b65f">size</a>() and <a href="#fbdfe3">rect</a>().
<p>Examples:
<a href="qtimage-qtimage-cpp.html#height">qtimage/qtimage.cpp</a>
<a href="xform-xform-cpp.html#height">xform/xform.cpp</a>
<a href="desktop-desktop-cpp.html#height">desktop/desktop.cpp</a>
<a href="scrollview-scrollview-cpp.html#height">scrollview/scrollview.cpp</a>
<a href="movies-main-cpp.html#height">movies/main.cpp</a>
<h3 class="fn">constchar*<a name="360626"></a>QPixmap::imageFormat(const<a href="qstring.html">QString</a>&fileName) <code>[static]</code></h3>
<p>Returns a string that specifies the image format of the file <em>fileName,</em>
or null if the file cannot be read or if the format cannot be recognized.
<p>The <a href="qimageio.html">QImageIO</a> documentation lists the supported image formats.
<p>See also <a href="#a728cf">load</a>() and <a href="#a38b1c">save</a>().
<h3 class="fn">bool<a name="7803c4"></a>QPixmap::isNull()const</h3>
<p>Returns TRUE if it is a null pixmap.
<p>A null pixmap has zero width, zero height and no contents.
You cannot draw in a null pixmap or <a href="qpaintdevice.html#35ae2e">bitBlt</a>() anything to it.
<p>Resizing an existing pixmap to (0,0) makes a pixmap into a null
pixmap.
<p>See also <a href="#b4f156">resize</a>().
<p>Examples:
<a href="qmag-qmag-cpp.html#isNull">qmag/qmag.cpp</a>
<a href="scrollview-scrollview-cpp.html#isNull">scrollview/scrollview.cpp</a>
<h3 class="fn">bool<a name="c0b272"></a>QPixmap::isQBitmap()const</h3>
<p>Returns TRUE if this is a <a href="qbitmap.html">QBitmap</a>, otherwise FALSE.
<h3 class="fn">bool<a name="a728cf"></a>QPixmap::load(const<a href="qstring.html">QString</a>&fileName, constchar*format, intconversion_flags)</h3>
<p>Loads a pixmap from the file <em>fileName.</em>
Returns TRUE if successful, or FALSE if the pixmap could not be loaded.
<p>If <em>format</em> is specified, the loader attempts to read the pixmap using the
specified format. If <em>format</em> is not specified (default),
the loader reads a few bytes from the header to guess the file format.
<p>See the <a href="#00951a">convertFromImage</a>() documentation for a description
of the <em>conversion_flags</em> argument.
<p>The <a href="qimageio.html">QImageIO</a> documentation lists the supported image formats and
explains how to add extra formats.
<p>See also <a href="#79475e">loadFromData</a>(), <a href="#a38b1c">save</a>(), <a href="#360626">imageFormat</a>(), <a href="qimage.html#42a675">QImage::load</a>() and <a href="qimageio.html">QImageIO</a>.
<p>Examples:
<a href="xform-xform-cpp.html#load">xform/xform.cpp</a>
<a href="scrollview-scrollview-cpp.html#load">scrollview/scrollview.cpp</a>
<a href="picture-picture-cpp.html#load">picture/picture.cpp</a>
<h3 class="fn">bool<a name="bdbe68"></a>QPixmap::load(const<a href="qstring.html">QString</a>&fileName, constchar*format=0, <a href="qpixmap.html#ColorMode">ColorMode</a>mode=Auto)</h3>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<h3 class="fn">bool<a name="79475e"></a>QPixmap::loadFromData(constuchar*buf, uintlen, constchar*format, intconversion_flags)</h3>
<p>Loads a pixmap from the binary data in <em>buf</em> (<em>len</em> bytes).
Returns TRUE if successful, or FALSE if the pixmap could not be loaded.
<p>If <em>format</em> is specified, the loader attempts to read the pixmap using the
specified format. If <em>format</em> is not specified (default),
the loader reads a few bytes from the header to guess the file format.
<p>See the <a href="#00951a">convertFromImage</a>() documentation for a description
of the <em>conversion_flags</em> argument.
<p>The <a href="qimageio.html">QImageIO</a> documentation lists the supported image formats and
explains how to add extra formats.
<p>See also <a href="#a728cf">load</a>(), <a href="#a38b1c">save</a>(), <a href="#360626">imageFormat</a>(), <a href="qimage.html#48cbcb">QImage::loadFromData</a>() and <a href="qimageio.html">QImageIO</a>.
<h3 class="fn">bool<a name="b0e017"></a>QPixmap::loadFromData(const<a href="qbytearray.html">QByteArray</a>&buf, constchar*format=0, intconversion_flags=0)</h3>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<h3 class="fn">bool<a name="32699f"></a>QPixmap::loadFromData(constuchar*buf, uintlen, constchar*format=0, <a href="qpixmap.html#ColorMode">ColorMode</a>mode=Auto)</h3>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<h3 class="fn">const<a href="qbitmap.html">QBitmap</a>*<a name="99119c"></a>QPixmap::mask()const</h3>
<p>Returns the mask bitmap, or null if no mask has been set.
<p>See also <a href="#68a75d">setMask</a>() and <a href="qbitmap.html">QBitmap</a>.
<h3 class="fn">int<a name="fa32cf"></a>QPixmap::metric(intm)const <code>[virtualprotected]</code></h3>
<p>Internal implementation of the virtual <a href="qpaintdevice.html#43eff7">QPaintDevice::metric</a>() function.
<p>Use the <a href="qpaintdevicemetrics.html">QPaintDeviceMetrics</a> class instead.
<p>Reimplemented from <a href="qpaintdevice.html#43eff7">QPaintDevice.</a>
<h3 class="fn">QPixmap&<a name="f29bf5"></a>QPixmap::operator=(const<a href="qimage.html">QImage</a>&image)</h3>
<p>Converts the image <em>image</em> to a pixmap that is assigned to this pixmap.
Returns a reference to the pixmap.
<p>See also <a href="#00951a">convertFromImage</a>().
<h3 class="fn">QPixmap&<a name="4a19b0"></a>QPixmap::operator=(constQPixmap&pixmap)</h3>
<p>Assigns the pixmap <em>pixmap</em> to this pixmap and returns a reference to
this pixmap.
<h3 class="fn">QPixmap::Optimization<a name="ae6199"></a>QPixmap::optimization()const</h3>
<p>Returns the optimization setting for this pixmap.
<p>The default optimization setting is <code>QPixmap::NormalOptim.</code> You may
change this settings in two ways:
<ul>
<li> Call <a href="#7675b8">setDefaultOptimization</a>() to set the default optimization
for all new pixmaps.
<li> Call <a href="#41f5cf">setOptimization</a>() to set a the optimization for individual
pixmaps.
</ul>
<p>See also <a href="#41f5cf">setOptimization</a>(), <a href="#7675b8">setDefaultOptimization</a>() and <a href="#3ad81f">defaultOptimization</a>().
<h3 class="fn"><a href="qrect.html">QRect</a><a name="fbdfe3"></a>QPixmap::rect()const</h3>
<p>Returns the enclosing rectangle (0,0,<a href="#86dbc5">width</a>(),<a href="#d5bb33">height</a>()) of the pixmap.
<p>See also <a href="#86dbc5">width</a>(), <a href="#d5bb33">height</a>() and <a href="#60b65f">size</a>().
<p>Examples:
<a href="xform-xform-cpp.html#rect">xform/xform.cpp</a>
<h3 class="fn">void<a name="b4f156"></a>QPixmap::resize(intw, inth)</h3>
<p>Resizes the pixmap to <em>w</em> width and <em>h</em> height. If either <em>w</em>
or <em>h</em> is less than 1, the pixmap becomes a null pixmap.
<p>If both <em>w</em> and <em>h</em> are greater than 0, a valid pixmap is created.
New pixels will be uninitialized (random) if the pixmap is expanded.
<p>Examples:
<a href="desktop-desktop-cpp.html#resize">desktop/desktop.cpp</a>
<h3 class="fn">void<a name="360eec"></a>QPixmap::resize(const<a href="qsize.html">QSize</a>&size)</h3>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<h3 class="fn">bool<a name="e02a5b"></a>QPixmap::save(const<a href="qstring.html">QString</a>&fileName, constchar*format)const</h3>
<p>Saves the pixmap to the file <em>fileName,</em> using the image file format
<em>format.</em> Returns TRUE if successful, or FALSE if the pixmap could not
be saved.
<p>See also <a href="#a728cf">load</a>(), <a href="#79475e">loadFromData</a>(), <a href="#360626">imageFormat</a>(), <a href="qimage.html#9f148a">QImage::save</a>() and <a href="qimageio.html">QImageIO</a>.
<h3 class="fn">bool<a name="a38b1c"></a>QPixmap::save(const<a href="qstring.html">QString</a>&fileName, constchar*format, intquality)const</h3>
<p>Saves the pixmap to the file <em>fileName,</em> using the image file format
<em>format</em> and a quality factor <em>quality. quality</em> must be in the
range [0,100] or -1. Specify 0 to obtain small compressed files, 100
for large uncompressed files and -1 to use the default settings.
Returns TRUE if successful, or FALSE if the pixmap could not be saved.
<p>See also <a href="#a728cf">load</a>(), <a href="#79475e">loadFromData</a>(), <a href="#360626">imageFormat</a>(), <a href="qimage.html#9f148a">QImage::save</a>() and <a href="qimageio.html">QImageIO</a>.
<p>Examples:
<a href="qmag-qmag-cpp.html#save">qmag/qmag.cpp</a>
<h3 class="fn">bool<a name="848613"></a>QPixmap::selfMask()const</h3>
<p>Returns TRUE if the pixmap's mask is identical to the pixmap itself.
<p>See also <a href="#99119c">mask</a>().
<h3 class="fn">int<a name="4f47d9"></a>QPixmap::serialNumber()const</h3>
<p>Returns a number that uniquely identifies the contents of this QPixmap object.
This means that multiple QPixmaps objects can have the same serial number
as long as they refer to the same contents.
The serial number is for example very useful for caching.
<p>See also <a href="qpixmapcache.html">QPixmapCache</a>.
<h3 class="fn">void<a name="7675b8"></a>QPixmap::setDefaultOptimization(<a href="qpixmap.html#Optimization">Optimization</a>optimization) <code>[static]</code></h3>
<p>Sets the default pixmap optimization.
<p>All <em>new</em> pixmaps that are created will use this default optimization.
You may also set optimization for individual pixmaps using the
<a href="#41f5cf">setOptimization</a>() function.
<p>The initial default optimization setting is <code>QPixmap::Normal.</code>
<p>See also <a href="#3ad81f">defaultOptimization</a>(), <a href="#41f5cf">setOptimization</a>() and <a href="#ae6199">optimization</a>().
<h3 class="fn">void<a name="68a75d"></a>QPixmap::setMask(const<a href="qbitmap.html">QBitmap</a>&newmask)</h3>
<p>Sets a mask bitmap.
<p>The <em>mask</em> bitmap defines the clip mask for this pixmap. Every pixel in
<em>mask</em> corresponds to a pixel in this pixmap. Pixel value 1 means opaque
and pixel value 0 means transparent. The mask must have the same size as
this pixmap.
<p>Setting a <a href="#7803c4">null</a> mask resets the mask,
<p>See also <a href="#99119c">mask</a>(), <a href="#20dfb1">createHeuristicMask</a>() and <a href="qbitmap.html">QBitmap</a>.
<h3 class="fn">void<a name="41f5cf"></a>QPixmap::setOptimization(<a href="qpixmap.html#Optimization">Optimization</a>optimization)</h3>
<p>Sets pixmap drawing optimization for this pixmap.
<p>The optimization setting affects pixmap operations, in particular
drawing of transparent pixmaps (<a href="qpaintdevice.html#35ae2e">bitBlt</a>() a pixmap with a mask set) and
pixmap transformations (the <a href="#ff5fcf">xForm</a>() function).
<p>Pixmap optimization involves keeping intermediate results in a cache
buffer and use the data in the cache to speed up bitBlt() and xForm().
The cost is more memory consumption, up to twice as much as an
unoptimized pixmap.
<p>Use the <a href="#7675b8">setDefaultOptimization</a>() to change the default optimization
for all new pixmaps.
<p>See also <a href="#ae6199">optimization</a>(), <a href="#7675b8">setDefaultOptimization</a>() and <a href="#3ad81f">defaultOptimization</a>().
<p>Examples:
<a href="desktop-desktop-cpp.html#setOptimization">desktop/desktop.cpp</a>
<h3 class="fn"><a href="qsize.html">QSize</a><a name="60b65f"></a>QPixmap::size()const</h3>
<p>Returns the size of the pixmap.
<p>See also <a href="#86dbc5">width</a>(), <a href="#d5bb33">height</a>() and <a href="#fbdfe3">rect</a>().
<p>Examples:
<a href="qtimage-qtimage-cpp.html#size">qtimage/qtimage.cpp</a>
<a href="movies-main-cpp.html#size">movies/main.cpp</a>
<h3 class="fn"><a href="qwmatrix.html">QWMatrix</a><a name="952384"></a>QPixmap::trueMatrix(const<a href="qwmatrix.html">QWMatrix</a>&matrix, intw, inth) <code>[static]</code></h3>
<p>Returns the actual matrix used for transforming a pixmap with <em>w</em>
width and <em>h</em> height.
<p>When transforming a pixmap with <a href="#ff5fcf">xForm</a>(), the transformation matrix
is internally adjusted to compensate for unwanted translation,
i.e. xForm() returns the smallest pixmap containing all transformed
points of the original pixmap.
<p>This function returns the modified matrix, which maps points
correctly from the original pixmap into the new pixmap.
<p>See also <a href="#ff5fcf">xForm</a>() and <a href="qwmatrix.html">QWMatrix</a>.
<h3 class="fn">int<a name="86dbc5"></a>QPixmap::width()const</h3>
<p>Returns the width of the pixmap.
<p>See also <a href="#d5bb33">height</a>(), <a href="#60b65f">size</a>() and <a href="#fbdfe3">rect</a>().
<p>Examples:
<a href="qtimage-qtimage-cpp.html#width">qtimage/qtimage.cpp</a>
<a href="xform-xform-cpp.html#width">xform/xform.cpp</a>
<a href="desktop-desktop-cpp.html#width">desktop/desktop.cpp</a>
<a href="scrollview-scrollview-cpp.html#width">scrollview/scrollview.cpp</a>
<a href="movies-main-cpp.html#width">movies/main.cpp</a>
<h3 class="fn">QPixmap<a name="ff5fcf"></a>QPixmap::xForm(const<a href="qwmatrix.html">QWMatrix</a>&matrix)const</h3>
<p>Returns a copy of the pixmap that is transformed using <em>matrix.</em>
<p>Qt uses this function to implement rotated text on window systems
that do not support such complex features.
<p>Example of how to manually draw a rotated text at (100,200) in a widget:
<pre> char *str = "Trolls R Qt"; // text to be drawn
<a href="qfont.html">QFont</a> f( "Charter", 24 ); // use Charter 24pt font
<a href="qpixmap.html">QPixmap</a> pm( 8, 8 );
<a href="qpainter.html">QPainter</a> p;
<a href="qrect.html">QRect</a> r; // text bounding rectangle
<a href="qpoint.html">QPoint</a> bl; // text baseline position
p.<a href="qpainter.html#02ed5d">begin</a>( &pm ); // first get the bounding
p.<a href="qpainter.html#998df2">setFont</a>( f ); // text rectangle
r = p.<a href="qpainter.html#73b2e5">fontMetrics</a>().boundingRect(str);
bl = -r.<a href="qrect.html#349186">topLeft</a>(); // get baseline position
p.<a href="qpainter.html#365784">end</a>();
pm.<a href="#b4f156">resize</a>( r.<a href="qrect.html#507cd9">size</a>() ); // resize to fit the text
pm.<a href="#6910a0">fill</a>( white ); // fills pm with white
p.<a href="qpainter.html#02ed5d">begin</a>( &pm ); // begin painting pm
p.<a href="qpainter.html#998df2">setFont</a>( f ); // set the font
p.<a href="qpainter.html#0183e4">setPen</a>( blue ); // set blue text color
p.<a href="qpainter.html#0f088f">drawText</a>( bl, str ); // draw the text
p.<a href="qpainter.html#365784">end</a>(); // painting done
<a href="qwmatrix.html">QWMatrix</a> m; // transformation matrix
m.<a href="qwmatrix.html#71020d">rotate</a>( -33.4 ); // rotate coordinate system
<a href="qpixmap.html">QPixmap</a> rp = pm.<a href="#ff5fcf">xForm</a>( m ); // rp is rotated pixmap
<a href="qwmatrix.html">QWMatrix</a> t = QPixmap::trueMatrix( m, pm.<a href="#86dbc5">width</a>(), pm.<a href="#d5bb33">height</a>() );
int x, y;
t.<a href="qwmatrix.html#83c725">map</a>( bl.<a href="qpoint.html#7e96b2">x</a>(),bl.<a href="qpoint.html#e48824">y</a>(), &x,&y ); // get pm's baseline pos in rp
<a href="qpaintdevice.html#35ae2e">bitBlt</a>( myWidget, 100-x, 200-y, // blt rp into a widget
&rp, 0, 0, -1, -1 );
</pre>
<p>This example outlines how Qt implements rotated text under X11.
The font calculation is the most tedious part. The rotation itself is
only 3 lines of code.
<p>If you want to draw rotated text, you do not have to implement all the
code above. The code below does exactly the same thing as the example
above, except that it uses a <a href="qpainter.html">QPainter</a>.
<p><pre> char *str = "Trolls R Qt"; // text to be drawn
<a href="qfont.html">QFont</a> f( "Charter", 24 ); // use Charter 24pt font
<a href="qpainter.html">QPainter</a> p;
p.<a href="qpainter.html#02ed5d">begin</a>( myWidget );
p.<a href="qpainter.html#eb778c">translate</a>( 100, 200 ); // translates coord system
p.<a href="qpainter.html#b5205c">rotate</a>( -33.4 ); // rotates it counterclockwise
p.<a href="qpainter.html#998df2">setFont</a>( f );
p.<a href="qpainter.html#0f088f">drawText</a>( 0, 0, str );
p.<a href="qpainter.html#365784">end</a>();
</pre>
<p>See also <a href="#952384">trueMatrix</a>(), <a href="qwmatrix.html">QWMatrix</a> and <a href="qpainter.html#862c4d">QPainter::setWorldMatrix</a>().
<p>Bugs and limitations:
<ul>
<li>2 and 4 bits pixmaps are not supported.
</ul>
<p>Examples:
<a href="qtimage-qtimage-cpp.html#xForm">qtimage/qtimage.cpp</a>
<a href="xform-xform-cpp.html#xForm">xform/xform.cpp</a>
<a href="qmag-qmag-cpp.html#xForm">qmag/qmag.cpp</a>
<a href="desktop-desktop-cpp.html#xForm">desktop/desktop.cpp</a>
<a href="movies-main-cpp.html#xForm">movies/main.cpp</a>
<hr><h2>Related Functions</h2>
<h3><a href="qdatastream.html">QDataStream</a> & <a name="3d1a55"></a>operator>> (<a href="qdatastream.html">QDataStream</a> & s, QPixmap & pixmap)</h3>
<p>Reads a pixmap from the stream.
<p>See also <a href="qpixmap.html#a728cf">QPixmap::load</a>() and <a href="datastreamformat.html">Format of the QDataStream operators</a>
<h3><a href="qdatastream.html">QDataStream</a> & <a name="6958b6"></a>operator<< (<a href="qdatastream.html">QDataStream</a> & s, const QPixmap & pixmap)</h3>
<p>Writes a pixmap to the stream as a PNG image.
<p>See also <a href="qpixmap.html#a38b1c">QPixmap::save</a>() and <a href="datastreamformat.html">Format of the QDataStream operators</a>
<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.2"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright © 1995-2001
<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>
|