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
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QTextDocument Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QTextDocument Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QTextDocument class holds formatted text that can be viewed
and edited using a <a href="qtextedit.html">QTextEdit</a>. <a href="#details">More...</a></p>
<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qtextdocument.html#FindFlag-enum">FindFlag</a></b> { FindBackward, FindCaseSensitively, FindWholeWords }</li><li><div class="fn" />class <b><a href="qtextdocument-findflags.html">FindFlags</a></b></li><li><div class="fn" />enum <b><a href="qtextdocument.html#MetaInformation-enum">MetaInformation</a></b> { DocumentTitle, DocumentUrl }</li><li><div class="fn" />enum <b><a href="qtextdocument.html#ResourceType-enum">ResourceType</a></b> { HtmlResource, ImageResource, StyleSheetResource, UserResource }</li><li><div class="fn" />enum <b><a href="qtextdocument.html#Stacks-enum">Stacks</a></b> { UndoStack, RedoStack, UndoAndRedoStacks }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qtextdocument.html#QTextDocument">__init__</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qtextdocument.html#QTextDocument-2">__init__</a></b> (<i>self</i>, QString <i>text</i>, QObject <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qtextdocument.html#addResource">addResource</a></b> (<i>self</i>, int <i>type</i>, QUrl <i>name</i>, QVariant <i>resource</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#adjustSize">adjustSize</a></b> (<i>self</i>)</li><li><div class="fn" />list-of-QTextFormat <b><a href="qtextdocument.html#allFormats">allFormats</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qtextdocument.html#availableRedoSteps">availableRedoSteps</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qtextdocument.html#availableUndoSteps">availableUndoSteps</a></b> (<i>self</i>)</li><li><div class="fn" />QTextBlock <b><a href="qtextdocument.html#begin">begin</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qtextdocument.html#blockCount">blockCount</a></b> (<i>self</i>)</li><li><div class="fn" />QChar <b><a href="qtextdocument.html#characterAt">characterAt</a></b> (<i>self</i>, int <i>pos</i>)</li><li><div class="fn" />int <b><a href="qtextdocument.html#characterCount">characterCount</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#clear">clear</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#clearUndoRedoStacks">clearUndoRedoStacks</a></b> (<i>self</i>, Stacks <i>stacks</i> = QTextDocument.UndoAndRedoStacks)</li><li><div class="fn" />QTextDocument <b><a href="qtextdocument.html#clone">clone</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" />QTextObject <b><a href="qtextdocument.html#createObject">createObject</a></b> (<i>self</i>, QTextFormat <i>f</i>)</li><li><div class="fn" />Qt.CursorMoveStyle <b><a href="qtextdocument.html#defaultCursorMoveStyle">defaultCursorMoveStyle</a></b> (<i>self</i>)</li><li><div class="fn" />QFont <b><a href="qtextdocument.html#defaultFont">defaultFont</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qtextdocument.html#defaultStyleSheet">defaultStyleSheet</a></b> (<i>self</i>)</li><li><div class="fn" />QTextOption <b><a href="qtextdocument.html#defaultTextOption">defaultTextOption</a></b> (<i>self</i>)</li><li><div class="fn" />QAbstractTextDocumentLayout <b><a href="qtextdocument.html#documentLayout">documentLayout</a></b> (<i>self</i>)</li><li><div class="fn" />float <b><a href="qtextdocument.html#documentMargin">documentMargin</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#drawContents">drawContents</a></b> (<i>self</i>, QPainter <i>p</i>, QRectF <i>rect</i> = QRectF())</li><li><div class="fn" />QTextBlock <b><a href="qtextdocument.html#end">end</a></b> (<i>self</i>)</li><li><div class="fn" />QTextCursor <b><a href="qtextdocument.html#find">find</a></b> (<i>self</i>, QString <i>subString</i>, int <i>position</i> = 0, FindFlags <i>options</i> = 0)</li><li><div class="fn" />QTextCursor <b><a href="qtextdocument.html#find-2">find</a></b> (<i>self</i>, QRegExp <i>expr</i>, int <i>position</i> = 0, FindFlags <i>options</i> = 0)</li><li><div class="fn" />QTextCursor <b><a href="qtextdocument.html#find-3">find</a></b> (<i>self</i>, QString <i>subString</i>, QTextCursor <i>cursor</i>, FindFlags <i>options</i> = 0)</li><li><div class="fn" />QTextCursor <b><a href="qtextdocument.html#find-4">find</a></b> (<i>self</i>, QRegExp <i>expr</i>, QTextCursor <i>cursor</i>, FindFlags <i>options</i> = 0)</li><li><div class="fn" />QTextBlock <b><a href="qtextdocument.html#findBlock">findBlock</a></b> (<i>self</i>, int <i>pos</i>)</li><li><div class="fn" />QTextBlock <b><a href="qtextdocument.html#findBlockByLineNumber">findBlockByLineNumber</a></b> (<i>self</i>, int <i>blockNumber</i>)</li><li><div class="fn" />QTextBlock <b><a href="qtextdocument.html#findBlockByNumber">findBlockByNumber</a></b> (<i>self</i>, int <i>blockNumber</i>)</li><li><div class="fn" />QTextBlock <b><a href="qtextdocument.html#firstBlock">firstBlock</a></b> (<i>self</i>)</li><li><div class="fn" />float <b><a href="qtextdocument.html#idealWidth">idealWidth</a></b> (<i>self</i>)</li><li><div class="fn" />float <b><a href="qtextdocument.html#indentWidth">indentWidth</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtextdocument.html#isEmpty">isEmpty</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtextdocument.html#isModified">isModified</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtextdocument.html#isRedoAvailable">isRedoAvailable</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtextdocument.html#isUndoAvailable">isUndoAvailable</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtextdocument.html#isUndoRedoEnabled">isUndoRedoEnabled</a></b> (<i>self</i>)</li><li><div class="fn" />QTextBlock <b><a href="qtextdocument.html#lastBlock">lastBlock</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qtextdocument.html#lineCount">lineCount</a></b> (<i>self</i>)</li><li><div class="fn" />QVariant <b><a href="qtextdocument.html#loadResource">loadResource</a></b> (<i>self</i>, int <i>type</i>, QUrl <i>name</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#markContentsDirty">markContentsDirty</a></b> (<i>self</i>, int <i>from</i>, int <i>length</i>)</li><li><div class="fn" />int <b><a href="qtextdocument.html#maximumBlockCount">maximumBlockCount</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qtextdocument.html#metaInformation">metaInformation</a></b> (<i>self</i>, MetaInformation <i>info</i>)</li><li><div class="fn" />QTextObject <b><a href="qtextdocument.html#object">object</a></b> (<i>self</i>, int <i>objectIndex</i>)</li><li><div class="fn" />QTextObject <b><a href="qtextdocument.html#objectForFormat">objectForFormat</a></b> (<i>self</i>, QTextFormat)</li><li><div class="fn" />int <b><a href="qtextdocument.html#pageCount">pageCount</a></b> (<i>self</i>)</li><li><div class="fn" />QSizeF <b><a href="qtextdocument.html#pageSize">pageSize</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#print">print</a></b> (<i>self</i>, QPrinter <i>printer</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#print">print_</a></b> (<i>self</i>, QPrinter <i>printer</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#redo">redo</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#redo-2">redo</a></b> (<i>self</i>, QTextCursor <i>cursor</i>)</li><li><div class="fn" />QVariant <b><a href="qtextdocument.html#resource">resource</a></b> (<i>self</i>, int <i>type</i>, QUrl <i>name</i>)</li><li><div class="fn" />int <b><a href="qtextdocument.html#revision">revision</a></b> (<i>self</i>)</li><li><div class="fn" />QTextFrame <b><a href="qtextdocument.html#rootFrame">rootFrame</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setDefaultCursorMoveStyle">setDefaultCursorMoveStyle</a></b> (<i>self</i>, Qt.CursorMoveStyle <i>style</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setDefaultFont">setDefaultFont</a></b> (<i>self</i>, QFont <i>font</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setDefaultStyleSheet">setDefaultStyleSheet</a></b> (<i>self</i>, QString <i>sheet</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setDefaultTextOption">setDefaultTextOption</a></b> (<i>self</i>, QTextOption <i>option</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setDocumentLayout">setDocumentLayout</a></b> (<i>self</i>, QAbstractTextDocumentLayout <i>layout</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setDocumentMargin">setDocumentMargin</a></b> (<i>self</i>, float <i>margin</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setHtml">setHtml</a></b> (<i>self</i>, QString <i>html</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setIndentWidth">setIndentWidth</a></b> (<i>self</i>, float <i>width</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setMaximumBlockCount">setMaximumBlockCount</a></b> (<i>self</i>, int <i>maximum</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setMetaInformation">setMetaInformation</a></b> (<i>self</i>, MetaInformation <i>info</i>, QString)</li><li><div class="fn" /><b><a href="qtextdocument.html#setModified">setModified</a></b> (<i>self</i>, bool <i>on</i> = True)</li><li><div class="fn" /><b><a href="qtextdocument.html#setPageSize">setPageSize</a></b> (<i>self</i>, QSizeF <i>size</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setPlainText">setPlainText</a></b> (<i>self</i>, QString <i>text</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setTextWidth">setTextWidth</a></b> (<i>self</i>, float <i>width</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setUndoRedoEnabled">setUndoRedoEnabled</a></b> (<i>self</i>, bool <i>enable</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#setUseDesignMetrics">setUseDesignMetrics</a></b> (<i>self</i>, bool <i>b</i>)</li><li><div class="fn" />QSizeF <b><a href="qtextdocument.html#size">size</a></b> (<i>self</i>)</li><li><div class="fn" />float <b><a href="qtextdocument.html#textWidth">textWidth</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qtextdocument.html#toHtml">toHtml</a></b> (<i>self</i>, QByteArray <i>encoding</i> = QByteArray())</li><li><div class="fn" />QString <b><a href="qtextdocument.html#toPlainText">toPlainText</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#undo">undo</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocument.html#undo-2">undo</a></b> (<i>self</i>, QTextCursor <i>cursor</i>)</li><li><div class="fn" />bool <b><a href="qtextdocument.html#useDesignMetrics">useDesignMetrics</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qtextdocument.html#blockCountChanged">blockCountChanged</a></b> (int)</li><li><div class="fn" />void <b><a href="qtextdocument.html#contentsChange">contentsChange</a></b> (int,int,int)</li><li><div class="fn" />void <b><a href="qtextdocument.html#contentsChanged">contentsChanged</a></b> ()</li><li><div class="fn" />void <b><a href="qtextdocument.html#cursorPositionChanged">cursorPositionChanged</a></b> (const QTextCursor&)</li><li><div class="fn" />void <b><a href="qtextdocument.html#documentLayoutChanged">documentLayoutChanged</a></b> ()</li><li><div class="fn" />void <b><a href="qtextdocument.html#modificationChanged">modificationChanged</a></b> (bool)</li><li><div class="fn" />void <b><a href="qtextdocument.html#redoAvailable">redoAvailable</a></b> (bool)</li><li><div class="fn" />void <b><a href="qtextdocument.html#undoAvailable">undoAvailable</a></b> (bool)</li><li><div class="fn" />void <b><a href="qtextdocument.html#undoCommandAdded">undoCommandAdded</a></b> ()</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTextDocument class holds formatted text that can be viewed
and edited using a <a href="qtextedit.html">QTextEdit</a>.</p>
<p>QTextDocument is a container for structured rich text documents,
providing support for styled text and various types of document
elements, such as lists, tables, frames, and images. They can be
created for use in a <a href="qtextedit.html">QTextEdit</a>, or
used independently.</p>
<p>Each document element is described by an associated format
object. Each format object is treated as a unique object by
QTextDocuments, and can be passed to <a href="qtextdocument.html#objectForFormat">objectForFormat</a>() to
obtain the document element that it is applied to.</p>
<p>A QTextDocument can be edited programmatically using a <a href="qtextcursor.html">QTextCursor</a>, and its contents can be
examined by traversing the document structure. The entire document
structure is stored as a hierarchy of document elements beneath the
root frame, found with the <a href="qtextdocument.html#rootFrame">rootFrame</a>() function.
Alternatively, if you just want to iterate over the textual
contents of the document you can use <a href="qtextdocument.html#begin">begin</a>(), <a href="qtextdocument.html#end">end</a>(), and <a href="qtextdocument.html#findBlock">findBlock</a>() to retrieve text
blocks that you can examine and iterate over.</p>
<p>The layout of a document is determined by the <a href="qtextdocument.html#documentLayout">documentLayout</a>(); you can
create your own <a href="qabstracttextdocumentlayout.html">QAbstractTextDocumentLayout</a>
subclass and set it using <a href="qtextdocument.html#setDocumentLayout">setDocumentLayout</a>() if
you want to use your own layout logic. The document's title and
other meta-information can be obtained by calling the <a href="qtextdocument.html#metaInformation">metaInformation</a>()
function. For documents that are exposed to users through the
<a href="qtextedit.html">QTextEdit</a> class, the document title is
also available via the <a href="qtextedit.html#documentTitle-prop">QTextEdit.documentTitle</a>()
function.</p>
<p>The <a href="qtextdocument.html#toPlainText">toPlainText</a>()
and <a href="qtextdocument.html#toHtml">toHtml</a>() convenience
functions allow you to retrieve the contents of the document as
plain text and HTML. The document's text can be searched using the
<a href="qtextdocument.html#find">find</a>() functions.</p>
<p>Undo/redo of operations performed on the document can be
controlled using the <a href="qtextdocument.html#undoRedoEnabled-prop">setUndoRedoEnabled</a>()
function. The undo/redo system can be controlled by an editor
widget through the <a href="qtextdocument.html#undo">undo</a>() and
<a href="qtextdocument.html#redo">redo</a>() slots; the document
also provides <a href="qtextdocument.html#contentsChanged">contentsChanged</a>(),
<a href="qtextdocument.html#undoAvailable">undoAvailable</a>(), and
<a href="qtextdocument.html#redoAvailable">redoAvailable</a>()
signals that inform connected editor widgets about the state of the
undo/redo system. The following are the undo/redo operations of a
QTextDocument:</p>
<ul>
<li>Insertion or removal of characters. A sequence of insertions or
removals within the same text block are regarded as a single
undo/redo operation.</li>
<li>Insertion or removal of text blocks. Sequences of insertion or
removals in a single operation (e.g., by selecting and then
deleting text) are regarded as a single undo/redo operation.</li>
<li>Text character format changes.</li>
<li>Text block format changes.</li>
<li>Text block group format changes.</li>
</ul>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="FindFlag-enum" />QTextDocument.FindFlag</h3><p>This enum describes the options available to <a href="qtextdocument.html">QTextDocument</a>'s find function. The options
can be OR-ed together from the following list:</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.FindBackward</tt></td>
<td class="topAlign"><tt>0x00001</tt></td>
<td class="topAlign">Search backwards instead of forwards.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QTextDocument.FindCaseSensitively</tt></td>
<td class="topAlign"><tt>0x00002</tt></td>
<td class="topAlign">By default find works case insensitive.
Specifying this option changes the behaviour to a case sensitive
find operation.</td>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.FindWholeWords</tt></td>
<td class="topAlign"><tt>0x00004</tt></td>
<td class="topAlign">Makes find match only complete words.</td>
</tr>
</table>
<p>The FindFlags type is a typedef for <a href="qflags.html">QFlags</a><FindFlag>. It stores an OR
combination of FindFlag values.</p>
<h3 class="fn"><a name="MetaInformation-enum" />QTextDocument.MetaInformation</h3><p>This enum describes the different types of meta information that
can be added to a document.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.DocumentTitle</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">The title of the document.</td>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.DocumentUrl</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">The url of the document. The <a href="qtextdocument.html#loadResource">loadResource</a>() function uses
this url as the base when loading relative resources.</td>
</tr>
</table>
<p><b>See also</b> <a href="qtextdocument.html#metaInformation">metaInformation</a>() and
<a href="qtextdocument.html#setMetaInformation">setMetaInformation</a>().</p>
<h3 class="fn"><a name="ResourceType-enum" />QTextDocument.ResourceType</h3><p>This enum describes the types of resources that can be loaded by
<a href="qtextdocument.html">QTextDocument</a>'s <a href="qtextdocument.html#loadResource">loadResource</a>() function.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.HtmlResource</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">The resource contains HTML.</td>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.ImageResource</tt></td>
<td class="topAlign"><tt>2</tt></td>
<td class="topAlign">The resource contains image data. Currently
supported data types are <a href="qvariant.html#Type-enum">QVariant.Pixmap</a> and <a href="qvariant.html#Type-enum">QVariant.Image</a>. If the corresponding
variant is of type <a href="qvariant.html#Type-enum">QVariant.ByteArray</a> then Qt attempts
to load the image using QImage.loadFromData. <a href="qvariant.html#Type-enum">QVariant.Icon</a> is currently not
supported. The icon needs to be converted to one of the supported
types first, for example using QIcon.pixmap.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QTextDocument.StyleSheetResource</tt></td>
<td class="topAlign"><tt>3</tt></td>
<td class="topAlign">The resource contains CSS.</td>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.UserResource</tt></td>
<td class="topAlign"><tt>100</tt></td>
<td class="topAlign">The first available value for user defined
resource types.</td>
</tr>
</table>
<p><b>See also</b> <a href="qtextdocument.html#loadResource">loadResource</a>().</p>
<h3 class="fn"><a name="Stacks-enum" />QTextDocument.Stacks</h3><table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.UndoStack</tt></td>
<td class="topAlign"><tt>0x01</tt></td>
<td class="topAlign">The undo stack.</td>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.RedoStack</tt></td>
<td class="topAlign"><tt>0x02</tt></td>
<td class="topAlign">The redo stack.</td>
</tr>
<tr>
<td class="topAlign"><tt>QTextDocument.UndoAndRedoStacks</tt></td>
<td class="topAlign"><tt>UndoStack | RedoStack</tt></td>
<td class="topAlign">Both the undo and redo stacks.</td>
</tr>
</table>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QTextDocument" />QTextDocument.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs an empty <a href="qtextdocument.html">QTextDocument</a> with the given
<i>parent</i>.</p>
<h3 class="fn"><a name="QTextDocument-2" />QTextDocument.__init__ (<i>self</i>, QString <i>text</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qtextdocument.html">QTextDocument</a>
containing the plain (unformatted) <i>text</i> specified, and with
the given <i>parent</i>.</p>
<h3 class="fn"><a name="addResource" />QTextDocument.addResource (<i>self</i>, int <i>type</i>, <a href="qurl.html">QUrl</a> <i>name</i>, QVariant <i>resource</i>)</h3><p>Adds the resource <i>resource</i> to the resource cache, using
<i>type</i> and <i>name</i> as identifiers. <i>type</i> should be a
value from <a href="qtextdocument.html#ResourceType-enum">QTextDocument.ResourceType</a>.</p>
<p>For example, you can add an image as a resource in order to
reference it from within the document:</p>
<pre class="cpp">
document<span class="operator">-</span><span class="operator">></span>addResource(<span class="type"><a href="qtextdocument.html">QTextDocument</a></span><span class="operator">.</span>ImageResource<span class="operator">,</span>
<span class="type"><a href="qurl.html">QUrl</a></span>(<span class="string">"mydata://image.png"</span>)<span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(image));
</pre>
<p>The image can be inserted into the document using the <a href="qtextcursor.html">QTextCursor</a> API:</p>
<pre class="cpp">
<span class="type"><a href="qtextimageformat.html">QTextImageFormat</a></span> imageFormat;
imageFormat<span class="operator">.</span>setName(<span class="string">"mydata://image.png"</span>);
cursor<span class="operator">.</span>insertImage(imageFormat);
</pre>
<p>Alternatively, you can insert images using the HTML <tt>img</tt>
tag:</p>
<pre class="cpp">
editor<span class="operator">-</span><span class="operator">></span>append(<span class="string">"<img src=\"mydata://image.png\" />"</span>);
</pre>
<h3 class="fn"><a name="adjustSize" />QTextDocument.adjustSize (<i>self</i>)</h3><p>Adjusts the document to a reasonable size.</p>
<p>This function was introduced in Qt 4.2.</p>
<p><b>See also</b> <a href="qtextdocument.html#idealWidth">idealWidth</a>(), <a href="qtextdocument.html#textWidth-prop">textWidth</a>, and <a href="qtextdocument.html#size-prop">size</a>.</p>
<h3 class="fn"><a name="allFormats" />list-of-QTextFormat QTextDocument.allFormats (<i>self</i>)</h3><p>Returns a vector of text formats for all the formats used in the
document.</p>
<h3 class="fn"><a name="availableRedoSteps" />int QTextDocument.availableRedoSteps (<i>self</i>)</h3><p>Returns the number of available redo steps.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also</b> <a href="qtextdocument.html#isRedoAvailable">isRedoAvailable</a>().</p>
<h3 class="fn"><a name="availableUndoSteps" />int QTextDocument.availableUndoSteps (<i>self</i>)</h3><p>Returns the number of available undo steps.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also</b> <a href="qtextdocument.html#isUndoAvailable">isUndoAvailable</a>().</p>
<h3 class="fn"><a name="begin" /><a href="qtextblock.html">QTextBlock</a> QTextDocument.begin (<i>self</i>)</h3><p>Returns the document's first text block.</p>
<p><b>See also</b> <a href="qtextdocument.html#firstBlock">firstBlock</a>().</p>
<h3 class="fn"><a name="blockCount" />int QTextDocument.blockCount (<i>self</i>)</h3><h3 class="fn"><a name="characterAt" />QChar QTextDocument.characterAt (<i>self</i>, int <i>pos</i>)</h3><p>Returns the character at position <i>pos</i>, or a null
character if the position is out of range.</p>
<p>This function was introduced in Qt 4.5.</p>
<p><b>See also</b> <a href="qtextdocument.html#characterCount">characterCount</a>().</p>
<h3 class="fn"><a name="characterCount" />int QTextDocument.characterCount (<i>self</i>)</h3><p>Returns the number of characters of this document.</p>
<p>This function was introduced in Qt 4.5.</p>
<p><b>See also</b> <a href="qtextdocument.html#blockCount-prop">blockCount</a>() and <a href="qtextdocument.html#characterAt">characterAt</a>().</p>
<h3 class="fn"><a name="clear" />QTextDocument.clear (<i>self</i>)</h3><p>Clears the document.</p>
<h3 class="fn"><a name="clearUndoRedoStacks" />QTextDocument.clearUndoRedoStacks (<i>self</i>, <a href="qtextdocument.html#Stacks-enum">Stacks</a> <i>stacks</i> = QTextDocument.UndoAndRedoStacks)</h3><p>Clears the stacks specified by <i>stacksToClear</i>.</p>
<p>This method clears any commands on the undo stack, the redo
stack, or both (the default). If commands are cleared, the
appropriate signals are emitted, <a href="qtextdocument.html#undoAvailable">QTextDocument.undoAvailable</a>()
or <a href="qtextdocument.html#redoAvailable">QTextDocument.redoAvailable</a>().</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also</b> <a href="qtextdocument.html#undoAvailable">QTextDocument.undoAvailable</a>()
and <a href="qtextdocument.html#redoAvailable">QTextDocument.redoAvailable</a>().</p>
<h3 class="fn"><a name="clone" /><a href="qtextdocument.html">QTextDocument</a> QTextDocument.clone (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Creates a new <a href="qtextdocument.html">QTextDocument</a>
that is a copy of this text document. <i>parent</i> is the parent
of the returned text document.</p>
<h3 class="fn"><a name="createObject" /><a href="qtextobject.html">QTextObject</a> QTextDocument.createObject (<i>self</i>, <a href="qtextformat.html">QTextFormat</a> <i>f</i>)</h3><p>Creates and returns a new document object (a <a href="qtextobject.html">QTextObject</a>), based on the given
<i>format</i>.</p>
<p>QTextObjects will always get created through this method, so you
must reimplement it if you use custom text objects inside your
document.</p>
<h3 class="fn"><a name="defaultCursorMoveStyle" /><a href="qt.html#CursorMoveStyle-enum">Qt.CursorMoveStyle</a> QTextDocument.defaultCursorMoveStyle (<i>self</i>)</h3><p>The default cursor movement style is used by all <a href="qtextcursor.html">QTextCursor</a> objects created from the
document. The default is <a href="qt.html#CursorMoveStyle-enum">Qt.LogicalMoveStyle</a>.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also</b> <a href="qtextdocument.html#setDefaultCursorMoveStyle">setDefaultCursorMoveStyle</a>().</p>
<h3 class="fn"><a name="defaultFont" /><a href="qfont.html">QFont</a> QTextDocument.defaultFont (<i>self</i>)</h3><h3 class="fn"><a name="defaultStyleSheet" />QString QTextDocument.defaultStyleSheet (<i>self</i>)</h3><h3 class="fn"><a name="defaultTextOption" /><a href="qtextoption.html">QTextOption</a> QTextDocument.defaultTextOption (<i>self</i>)</h3><h3 class="fn"><a name="documentLayout" /><a href="qabstracttextdocumentlayout.html">QAbstractTextDocumentLayout</a> QTextDocument.documentLayout (<i>self</i>)</h3><p>Returns the document layout for this document.</p>
<p><b>See also</b> <a href="qtextdocument.html#setDocumentLayout">setDocumentLayout</a>().</p>
<h3 class="fn"><a name="documentMargin" />float QTextDocument.documentMargin (<i>self</i>)</h3><h3 class="fn"><a name="drawContents" />QTextDocument.drawContents (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>p</i>, <a href="qrectf.html">QRectF</a> <i>rect</i> = QRectF())</h3><p>Draws the content of the document with painter <i>p</i>, clipped
to <i>rect</i>. If <i>rect</i> is a null rectangle (default) then
the document is painted unclipped.</p>
<p>This function was introduced in Qt 4.2.</p>
<h3 class="fn"><a name="end" /><a href="qtextblock.html">QTextBlock</a> QTextDocument.end (<i>self</i>)</h3><p>This function returns a block to test for the end of the
document while iterating over it.</p>
<pre class="cpp">
<span class="keyword">for</span> (<span class="type"><a href="qtextblock.html">QTextBlock</a></span> it <span class="operator">=</span> doc<span class="operator">-</span><span class="operator">></span>begin(); it <span class="operator">!</span><span class="operator">=</span> doc<span class="operator">-</span><span class="operator">></span>end(); it <span class="operator">=</span> it<span class="operator">.</span>next())
cout <span class="operator"><</span><span class="operator"><</span> it<span class="operator">.</span>text()<span class="operator">.</span>toStdString() <span class="operator"><</span><span class="operator"><</span> endl;
</pre>
<p>The block returned is invalid and represents the block after the
last block in the document. You can use <a href="qtextdocument.html#lastBlock">lastBlock</a>() to retrieve the last
valid block of the document.</p>
<p><b>See also</b> <a href="qtextdocument.html#lastBlock">lastBlock</a>().</p>
<h3 class="fn"><a name="find" /><a href="qtextcursor.html">QTextCursor</a> QTextDocument.find (<i>self</i>, QString <i>subString</i>, int <i>position</i> = 0, <a href="qtextdocument-findflags.html">FindFlags</a> <i>options</i> = 0)</h3><p>Finds the next occurrence of the string, <i>subString</i>, in
the document. The search starts at the position of the given
<i>cursor</i>, and proceeds forwards through the document unless
specified otherwise in the search options. The <i>options</i>
control the type of search performed.</p>
<p>Returns a cursor with the match selected if <i>subString</i> was
found; otherwise returns a null cursor.</p>
<p>If the given <i>cursor</i> has a selection, the search begins
after the selection; otherwise it begins at the cursor's
position.</p>
<p>By default the search is case-sensitive, and can match text
anywhere in the document.</p>
<h3 class="fn"><a name="find-2" /><a href="qtextcursor.html">QTextCursor</a> QTextDocument.find (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>expr</i>, int <i>position</i> = 0, <a href="qtextdocument-findflags.html">FindFlags</a> <i>options</i> = 0)</h3><p>Finds the next occurrence, matching the regular expression,
<i>expr</i>, in the document. The search starts at the position of
the given <i>cursor</i>, and proceeds forwards through the document
unless specified otherwise in the search options. The
<i>options</i> control the type of search performed. The <a href="qtextdocument.html#FindFlag-enum">FindCaseSensitively</a> option
is ignored for this overload, use QRegExp.caseSensitivity
instead.</p>
<p>Returns a cursor with the match selected if a match was found;
otherwise returns a null cursor.</p>
<p>If the given <i>cursor</i> has a selection, the search begins
after the selection; otherwise it begins at the cursor's
position.</p>
<p>By default the search is case-sensitive, and can match text
anywhere in the document.</p>
<h3 class="fn"><a name="find-3" /><a href="qtextcursor.html">QTextCursor</a> QTextDocument.find (<i>self</i>, QString <i>subString</i>, <a href="qtextcursor.html">QTextCursor</a> <i>cursor</i>, <a href="qtextdocument-findflags.html">FindFlags</a> <i>options</i> = 0)</h3><p>This is an overloaded function.</p>
<p>Finds the next occurrence of the string, <i>subString</i>, in
the document. The search starts at the given <i>position</i>, and
proceeds forwards through the document unless specified otherwise
in the search options. The <i>options</i> control the type of
search performed.</p>
<p>Returns a cursor with the match selected if <i>subString</i> was
found; otherwise returns a null cursor.</p>
<p>If the <i>position</i> is 0 (the default) the search begins from
the beginning of the document; otherwise it begins at the specified
position.</p>
<h3 class="fn"><a name="find-4" /><a href="qtextcursor.html">QTextCursor</a> QTextDocument.find (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>expr</i>, <a href="qtextcursor.html">QTextCursor</a> <i>cursor</i>, <a href="qtextdocument-findflags.html">FindFlags</a> <i>options</i> = 0)</h3><p>This is an overloaded function.</p>
<p>Finds the next occurrence, matching the regular expression,
<i>expr</i>, in the document. The search starts at the given
<i>position</i>, and proceeds forwards through the document unless
specified otherwise in the search options. The <i>options</i>
control the type of search performed. The <a href="qtextdocument.html#FindFlag-enum">FindCaseSensitively</a> option
is ignored for this overload, use QRegExp.caseSensitivity
instead.</p>
<p>Returns a cursor with the match selected if a match was found;
otherwise returns a null cursor.</p>
<p>If the <i>position</i> is 0 (the default) the search begins from
the beginning of the document; otherwise it begins at the specified
position.</p>
<h3 class="fn"><a name="findBlock" /><a href="qtextblock.html">QTextBlock</a> QTextDocument.findBlock (<i>self</i>, int <i>pos</i>)</h3><p>Returns the text block that contains the <i>pos</i>-th
character.</p>
<h3 class="fn"><a name="findBlockByLineNumber" /><a href="qtextblock.html">QTextBlock</a> QTextDocument.findBlockByLineNumber (<i>self</i>, int <i>blockNumber</i>)</h3><p>Returns the text block that contains the specified
<i>lineNumber</i>.</p>
<p>This function was introduced in Qt 4.5.</p>
<p><b>See also</b> <a href="qtextblock.html#firstLineNumber">QTextBlock.firstLineNumber</a>().</p>
<h3 class="fn"><a name="findBlockByNumber" /><a href="qtextblock.html">QTextBlock</a> QTextDocument.findBlockByNumber (<i>self</i>, int <i>blockNumber</i>)</h3><p>Returns the text block with the specified
<i>blockNumber</i>.</p>
<p>This function was introduced in Qt 4.4.</p>
<p><b>See also</b> <a href="qtextblock.html#blockNumber">QTextBlock.blockNumber</a>().</p>
<h3 class="fn"><a name="firstBlock" /><a href="qtextblock.html">QTextBlock</a> QTextDocument.firstBlock (<i>self</i>)</h3><p>Returns the document's first text block.</p>
<p>This function was introduced in Qt 4.4.</p>
<h3 class="fn"><a name="idealWidth" />float QTextDocument.idealWidth (<i>self</i>)</h3><p>Returns the ideal width of the text document. The ideal width is
the actually used width of the document without optional alignments
taken into account. It is always <= <a href="qtextdocument.html#size-prop">size</a>().width().</p>
<p>This function was introduced in Qt 4.2.</p>
<p><b>See also</b> <a href="qtextdocument.html#adjustSize">adjustSize</a>() and <a href="qtextdocument.html#textWidth-prop">textWidth</a>.</p>
<h3 class="fn"><a name="indentWidth" />float QTextDocument.indentWidth (<i>self</i>)</h3><h3 class="fn"><a name="isEmpty" />bool QTextDocument.isEmpty (<i>self</i>)</h3><p>Returns true if the document is empty; otherwise returns
false.</p>
<h3 class="fn"><a name="isModified" />bool QTextDocument.isModified (<i>self</i>)</h3><h3 class="fn"><a name="isRedoAvailable" />bool QTextDocument.isRedoAvailable (<i>self</i>)</h3><p>Returns true if redo is available; otherwise returns false.</p>
<p><b>See also</b> <a href="qtextdocument.html#isUndoAvailable">isUndoAvailable</a>() and
<a href="qtextdocument.html#availableRedoSteps">availableRedoSteps</a>().</p>
<h3 class="fn"><a name="isUndoAvailable" />bool QTextDocument.isUndoAvailable (<i>self</i>)</h3><p>Returns true if undo is available; otherwise returns false.</p>
<p><b>See also</b> <a href="qtextdocument.html#isRedoAvailable">isRedoAvailable</a>() and
<a href="qtextdocument.html#availableUndoSteps">availableUndoSteps</a>().</p>
<h3 class="fn"><a name="isUndoRedoEnabled" />bool QTextDocument.isUndoRedoEnabled (<i>self</i>)</h3><h3 class="fn"><a name="lastBlock" /><a href="qtextblock.html">QTextBlock</a> QTextDocument.lastBlock (<i>self</i>)</h3><p>Returns the document's last (valid) text block.</p>
<p>This function was introduced in Qt 4.4.</p>
<h3 class="fn"><a name="lineCount" />int QTextDocument.lineCount (<i>self</i>)</h3><p>Returns the number of lines of this document (if the layout
supports this). Otherwise, this is identical to the number of
blocks.</p>
<p>This function was introduced in Qt 4.5.</p>
<p><b>See also</b> <a href="qtextdocument.html#blockCount-prop">blockCount</a>() and <a href="qtextdocument.html#characterCount">characterCount</a>().</p>
<h3 class="fn"><a name="loadResource" />QVariant QTextDocument.loadResource (<i>self</i>, int <i>type</i>, <a href="qurl.html">QUrl</a> <i>name</i>)</h3><p>Loads data of the specified <i>type</i> from the resource with
the given <i>name</i>.</p>
<p>This function is called by the rich text engine to request data
that isn't directly stored by <a href="qtextdocument.html">QTextDocument</a>, but still associated with
it. For example, images are referenced indirectly by the name
attribute of a <a href="qtextimageformat.html">QTextImageFormat</a>
object.</p>
<p>When called by Qt, <i>type</i> is one of the values of <a href="qtextdocument.html#ResourceType-enum">QTextDocument.ResourceType</a>.</p>
<p>If the <a href="qtextdocument.html">QTextDocument</a> is a child
object of a <a href="qtextedit.html">QTextEdit</a>, <a href="qtextbrowser.html">QTextBrowser</a>, or a <a href="qtextdocument.html">QTextDocument</a> itself then the default
implementation tries to retrieve the data from the parent.</p>
<h3 class="fn"><a name="markContentsDirty" />QTextDocument.markContentsDirty (<i>self</i>, int <i>from</i>, int <i>length</i>)</h3><p>Marks the contents specified by the given <i>position</i> and
<i>length</i> as "dirty", informing the document that it needs to
be laid out again.</p>
<h3 class="fn"><a name="maximumBlockCount" />int QTextDocument.maximumBlockCount (<i>self</i>)</h3><h3 class="fn"><a name="metaInformation" />QString QTextDocument.metaInformation (<i>self</i>, <a href="qtextdocument.html#MetaInformation-enum">MetaInformation</a> <i>info</i>)</h3><p>Returns meta information about the document of the type
specified by <i>info</i>.</p>
<p><b>See also</b> <a href="qtextdocument.html#setMetaInformation">setMetaInformation</a>().</p>
<h3 class="fn"><a name="object" /><a href="qtextobject.html">QTextObject</a> QTextDocument.object (<i>self</i>, int <i>objectIndex</i>)</h3><p>Returns the text object associated with the given
<i>objectIndex</i>.</p>
<h3 class="fn"><a name="objectForFormat" /><a href="qtextobject.html">QTextObject</a> QTextDocument.objectForFormat (<i>self</i>, <a href="qtextformat.html">QTextFormat</a>)</h3><p>Returns the text object associated with the format <i>f</i>.</p>
<h3 class="fn"><a name="pageCount" />int QTextDocument.pageCount (<i>self</i>)</h3><p>returns the number of pages in this document.</p>
<h3 class="fn"><a name="pageSize" /><a href="qsizef.html">QSizeF</a> QTextDocument.pageSize (<i>self</i>)</h3><h3 class="fn"><a name="print" />QTextDocument.print (<i>self</i>, <a href="qprinter.html">QPrinter</a> <i>printer</i>)</h3><p>Prints the document to the given <i>printer</i>. The <a href="qprinter.html">QPrinter</a> must be set up before being used with
this function.</p>
<p>This is only a convenience method to print the whole document to
the printer.</p>
<p>If the document is already paginated through a specified height
in the <a href="qtextdocument.html#pageSize-prop">pageSize</a>()
property it is printed as-is.</p>
<p>If the document is not paginated, like for example a document
used in a <a href="qtextedit.html">QTextEdit</a>, then a temporary
copy of the document is created and the copy is broken into
multiple pages according to the size of the <a href="qprinter.html">QPrinter</a>'s paperRect(). By default a 2 cm
margin is set around the document contents. In addition the current
page number is printed at the bottom of each page.</p>
<p>Note that <a href="qprinter.html#PrintRange-enum">QPrinter.Selection</a> is not
supported as print range with this function since the selection is
a property of <a href="qtextcursor.html">QTextCursor</a>. If you
have a <a href="qtextedit.html">QTextEdit</a> associated with your
<a href="qtextdocument.html">QTextDocument</a> then you can use
<a href="qtextedit.html">QTextEdit</a>'s print() function because
<a href="qtextedit.html">QTextEdit</a> has access to the user's
selection.</p>
<p><b>See also</b> <a href="qtextedit.html#print">QTextEdit.print</a>().</p>
<h3 class="fn"><a name="print" />QTextDocument.print_ (<i>self</i>, <a href="qprinter.html">QPrinter</a> <i>printer</i>)</h3><p>Prints the document to the given <i>printer</i>. The <a href="qprinter.html">QPrinter</a> must be set up before being used with
this function.</p>
<p>This is only a convenience method to print the whole document to
the printer.</p>
<p>If the document is already paginated through a specified height
in the <a href="qtextdocument.html#pageSize-prop">pageSize</a>()
property it is printed as-is.</p>
<p>If the document is not paginated, like for example a document
used in a <a href="qtextedit.html">QTextEdit</a>, then a temporary
copy of the document is created and the copy is broken into
multiple pages according to the size of the <a href="qprinter.html">QPrinter</a>'s paperRect(). By default a 2 cm
margin is set around the document contents. In addition the current
page number is printed at the bottom of each page.</p>
<p>Note that <a href="qprinter.html#PrintRange-enum">QPrinter.Selection</a> is not
supported as print range with this function since the selection is
a property of <a href="qtextcursor.html">QTextCursor</a>. If you
have a <a href="qtextedit.html">QTextEdit</a> associated with your
<a href="qtextdocument.html">QTextDocument</a> then you can use
<a href="qtextedit.html">QTextEdit</a>'s print() function because
<a href="qtextedit.html">QTextEdit</a> has access to the user's
selection.</p>
<p><b>See also</b> <a href="qtextedit.html#print">QTextEdit.print</a>().</p>
<h3 class="fn"><a name="redo" />QTextDocument.redo (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void redo()</tt>.</p><p>Redoes the last editing operation on the document if <a href="qtextdocument.html#isRedoAvailable">redo is available</a>.</p>
<p>The provided <i>cursor</i> is positioned at the end of the
location where the edition operation was redone.</p>
<p>This function was introduced in Qt 4.2.</p>
<h3 class="fn"><a name="redo-2" />QTextDocument.redo (<i>self</i>, <a href="qtextcursor.html">QTextCursor</a> <i>cursor</i>)</h3><p>This is an overloaded function.</p>
<p>Redoes the last editing operation on the document if <a href="qtextdocument.html#isRedoAvailable">redo is available</a>.</p>
<h3 class="fn"><a name="resource" />QVariant QTextDocument.resource (<i>self</i>, int <i>type</i>, <a href="qurl.html">QUrl</a> <i>name</i>)</h3><p>Returns data of the specified <i>type</i> from the resource with
the given <i>name</i>.</p>
<p>This function is called by the rich text engine to request data
that isn't directly stored by <a href="qtextdocument.html">QTextDocument</a>, but still associated with
it. For example, images are referenced indirectly by the name
attribute of a <a href="qtextimageformat.html">QTextImageFormat</a>
object.</p>
<p>Resources are cached internally in the document. If a resource
can not be found in the cache, loadResource is called to try to
load the resource. loadResource should then use addResource to add
the resource to the cache.</p>
<p><b>See also</b> <a href="qtextdocument.html#ResourceType-enum">QTextDocument.ResourceType</a>.</p>
<h3 class="fn"><a name="revision" />int QTextDocument.revision (<i>self</i>)</h3><p>Returns the document's revision (if undo is enabled).</p>
<p>The revision is guaranteed to increase when a document that is
not modified is edited.</p>
<p>This function was introduced in Qt 4.4.</p>
<p><b>See also</b> <a href="qtextblock.html#revision">QTextBlock.revision</a>() and <a href="qtextdocument.html#modified-prop">isModified</a>().</p>
<h3 class="fn"><a name="rootFrame" /><a href="qtextframe.html">QTextFrame</a> QTextDocument.rootFrame (<i>self</i>)</h3><p>Returns the document's root frame.</p>
<h3 class="fn"><a name="setDefaultCursorMoveStyle" />QTextDocument.setDefaultCursorMoveStyle (<i>self</i>, <a href="qt.html#CursorMoveStyle-enum">Qt.CursorMoveStyle</a> <i>style</i>)</h3><p>Sets the default cursor movement style to the given
<i>style</i>.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also</b> <a href="qtextdocument.html#defaultCursorMoveStyle">defaultCursorMoveStyle</a>().</p>
<h3 class="fn"><a name="setDefaultFont" />QTextDocument.setDefaultFont (<i>self</i>, <a href="qfont.html">QFont</a> <i>font</i>)</h3><h3 class="fn"><a name="setDefaultStyleSheet" />QTextDocument.setDefaultStyleSheet (<i>self</i>, QString <i>sheet</i>)</h3><h3 class="fn"><a name="setDefaultTextOption" />QTextDocument.setDefaultTextOption (<i>self</i>, <a href="qtextoption.html">QTextOption</a> <i>option</i>)</h3><h3 class="fn"><a name="setDocumentLayout" />QTextDocument.setDocumentLayout (<i>self</i>, <a href="qabstracttextdocumentlayout.html">QAbstractTextDocumentLayout</a> <i>layout</i>)</h3><p>The <i>layout</i> argument has it's ownership transferred to Qt.</p><p>Sets the document to use the given <i>layout</i>. The previous
layout is deleted.</p>
<p><b>See also</b> <a href="qtextdocument.html#documentLayoutChanged">documentLayoutChanged</a>().</p>
<h3 class="fn"><a name="setDocumentMargin" />QTextDocument.setDocumentMargin (<i>self</i>, float <i>margin</i>)</h3><h3 class="fn"><a name="setHtml" />QTextDocument.setHtml (<i>self</i>, QString <i>html</i>)</h3><p>Replaces the entire contents of the document with the given
HTML-formatted text in the <i>html</i> string.</p>
<p>The HTML formatting is respected as much as possible; for
example, "<b>bold</b> text" will produce text where the
first word has a font weight that gives it a bold appearance:
"<b>bold</b> text".</p>
<p><b>Note:</b> It is the responsibility of the caller to make sure
that the text is correctly decoded when a <a href="qstring.html">QString</a> containing HTML is created and passed to
setHtml().</p>
<p><b>See also</b> <a href="qtextdocument.html#setPlainText">setPlainText</a>() and <a href="richtext-html-subset.html">Supported HTML Subset</a>.</p>
<h3 class="fn"><a name="setIndentWidth" />QTextDocument.setIndentWidth (<i>self</i>, float <i>width</i>)</h3><h3 class="fn"><a name="setMaximumBlockCount" />QTextDocument.setMaximumBlockCount (<i>self</i>, int <i>maximum</i>)</h3><h3 class="fn"><a name="setMetaInformation" />QTextDocument.setMetaInformation (<i>self</i>, <a href="qtextdocument.html#MetaInformation-enum">MetaInformation</a> <i>info</i>, QString)</h3><p>Sets the document's meta information of the type specified by
<i>info</i> to the given <i>string</i>.</p>
<p><b>See also</b> <a href="qtextdocument.html#metaInformation">metaInformation</a>().</p>
<h3 class="fn"><a name="setModified" />QTextDocument.setModified (<i>self</i>, bool <i>on</i> = True)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setModified(bool = 1)</tt>.</p><h3 class="fn"><a name="setPageSize" />QTextDocument.setPageSize (<i>self</i>, <a href="qsizef.html">QSizeF</a> <i>size</i>)</h3><h3 class="fn"><a name="setPlainText" />QTextDocument.setPlainText (<i>self</i>, QString <i>text</i>)</h3><p>Replaces the entire contents of the document with the given
plain <i>text</i>.</p>
<p><b>See also</b> <a href="qtextdocument.html#setHtml">setHtml</a>().</p>
<h3 class="fn"><a name="setTextWidth" />QTextDocument.setTextWidth (<i>self</i>, float <i>width</i>)</h3><h3 class="fn"><a name="setUndoRedoEnabled" />QTextDocument.setUndoRedoEnabled (<i>self</i>, bool <i>enable</i>)</h3><h3 class="fn"><a name="setUseDesignMetrics" />QTextDocument.setUseDesignMetrics (<i>self</i>, bool <i>b</i>)</h3><h3 class="fn"><a name="size" /><a href="qsizef.html">QSizeF</a> QTextDocument.size (<i>self</i>)</h3><h3 class="fn"><a name="textWidth" />float QTextDocument.textWidth (<i>self</i>)</h3><h3 class="fn"><a name="toHtml" />QString QTextDocument.toHtml (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>encoding</i> = QByteArray())</h3><p>Returns a string containing an HTML representation of the
document.</p>
<p>The <i>encoding</i> parameter specifies the value for the
charset attribute in the html header. For example if 'utf-8' is
specified then the beginning of the generated html will look like
this:</p>
<pre class="cpp">
<span class="operator"><</span>html<span class="operator">></span><span class="operator"><</span>head<span class="operator">></span><span class="operator"><</span>meta http<span class="operator">-</span>equiv<span class="operator">=</span><span class="string">"Content-Type"</span> content<span class="operator">=</span><span class="string">"text/html; charset=utf-8"</span><span class="operator">></span><span class="operator"><</span><span class="operator">/</span>head<span class="operator">></span><span class="operator"><</span>body<span class="operator">></span><span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
</pre>
<p>If no encoding is specified then no such meta information is
generated.</p>
<p>If you later on convert the returned html string into a byte
array for transmission over a network or when saving to disk you
should specify the encoding you're going to use for the conversion
to a byte array here.</p>
<p><b>See also</b> <a href="richtext-html-subset.html">Supported
HTML Subset</a>.</p>
<h3 class="fn"><a name="toPlainText" />QString QTextDocument.toPlainText (<i>self</i>)</h3><p>Returns the plain text contained in the document. If you want
formatting information use a <a href="qtextcursor.html">QTextCursor</a> instead.</p>
<p><b>See also</b> <a href="qtextdocument.html#toHtml">toHtml</a>().</p>
<h3 class="fn"><a name="undo" />QTextDocument.undo (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void undo()</tt>.</p><p>Undoes the last editing operation on the document if undo is
available. The provided <i>cursor</i> is positioned at the end of
the location where the edition operation was undone.</p>
<p>See the <a href="qundo.html">Qt Undo Framework</a> documentation
for details.</p>
<p>This function was introduced in Qt 4.2.</p>
<p><b>See also</b> <a href="qtextdocument.html#undoAvailable">undoAvailable</a>() and <a href="qtextdocument.html#undoRedoEnabled-prop">isUndoRedoEnabled</a>().</p>
<h3 class="fn"><a name="undo-2" />QTextDocument.undo (<i>self</i>, <a href="qtextcursor.html">QTextCursor</a> <i>cursor</i>)</h3><p>This is an overloaded function.</p>
<h3 class="fn"><a name="useDesignMetrics" />bool QTextDocument.useDesignMetrics (<i>self</i>)</h3><hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="blockCountChanged" />void blockCountChanged (int)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted when the total number of text blocks in
the document changes. The value passed in <i>newBlockCount</i> is
the new total.</p>
<p>This function was introduced in Qt 4.3.</p>
<h3 class="fn"><a name="contentsChange" />void contentsChange (int,int,int)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the document's content changes;
for example, when text is inserted or deleted, or when formatting
is applied.</p>
<p>Information is provided about the <i>position</i> of the
character in the document where the change occurred, the number of
characters removed (<i>charsRemoved</i>), and the number of
characters added (<i>charsAdded</i>).</p>
<p>The signal is emitted before the document's layout manager is
notified about the change. This hook allows you to implement syntax
highlighting for the document.</p>
<p><b>See also</b> <a href="qabstracttextdocumentlayout.html#documentChanged">QAbstractTextDocumentLayout.documentChanged</a>()
and <a href="qtextdocument.html#contentsChanged">contentsChanged</a>().</p>
<h3 class="fn"><a name="contentsChanged" />void contentsChanged ()</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the document's content changes;
for example, when text is inserted or deleted, or when formatting
is applied.</p>
<p><b>See also</b> <a href="qtextdocument.html#contentsChange">contentsChange</a>().</p>
<h3 class="fn"><a name="cursorPositionChanged" />void cursorPositionChanged (const QTextCursor&)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the position of a cursor changed
due to an editing operation. The cursor that changed is passed in
<i>cursor</i>. If you need a signal when the cursor is moved with
the arrow keys you can use the <a href="qtextedit.html#cursorPositionChanged">cursorPositionChanged()</a>
signal in <a href="qtextedit.html">QTextEdit</a>.</p>
<h3 class="fn"><a name="documentLayoutChanged" />void documentLayoutChanged ()</h3><p>This is the default overload of this signal.</p><p>This signal is emitted when a new document layout is set.</p>
<p>This function was introduced in Qt 4.4.</p>
<p><b>See also</b> <a href="qtextdocument.html#setDocumentLayout">setDocumentLayout</a>().</p>
<h3 class="fn"><a name="modificationChanged" />void modificationChanged (bool)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the content of the document
changes in a way that affects the modification state. If
<i>changed</i> is true, the document has been modified; otherwise
it is false.</p>
<p>For example, calling setModified(false) on a document and then
inserting text causes the signal to get emitted. If you undo that
operation, causing the document to return to its original
unmodified state, the signal will get emitted again.</p>
<h3 class="fn"><a name="redoAvailable" />void redoAvailable (bool)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever redo operations become available
(<i>available</i> is true) or unavailable (<i>available</i> is
false).</p>
<h3 class="fn"><a name="undoAvailable" />void undoAvailable (bool)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever undo operations become available
(<i>available</i> is true) or unavailable (<i>available</i> is
false).</p>
<p>See the <a href="qundo.html">Qt Undo Framework</a> documentation
for details.</p>
<p><b>See also</b> <a href="qtextdocument.html#undo">undo</a>() and
<a href="qtextdocument.html#undoRedoEnabled-prop">isUndoRedoEnabled</a>().</p>
<h3 class="fn"><a name="undoCommandAdded" />void undoCommandAdded ()</h3><p>This is the default overload of this signal.</p><p>This signal is emitted every time a new level of undo is added
to the <a href="qtextdocument.html">QTextDocument</a>.</p>
<p>This function was introduced in Qt 4.4.</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.9.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.2</td></tr></table></div></address></body></html>
|