Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtextedit.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qtextedit_p.h"
5#if QT_CONFIG(lineedit)
6#include "qlineedit.h"
7#endif
8#if QT_CONFIG(textbrowser)
9#include "qtextbrowser.h"
10#endif
11
12#include <qfont.h>
13#include <qpainter.h>
14#include <qevent.h>
15#include <qdebug.h>
16#if QT_CONFIG(draganddrop)
17#include <qdrag.h>
18#endif
19#include <qclipboard.h>
20#if QT_CONFIG(menu)
21#include <qmenu.h>
22#endif
23#include <qstyle.h>
24#include <qtimer.h>
25#if QT_CONFIG(accessibility)
26#include <qaccessible.h>
27#endif
28#include "private/qtextdocumentlayout_p.h"
29#include "qtextdocument.h"
30#include "private/qtextdocument_p.h"
31#include "qtextlist.h"
32#include "private/qwidgettextcontrol_p.h"
33
34#include <qtextformat.h>
35#include <qdatetime.h>
36#include <qapplication.h>
37#include <private/qapplication_p.h>
38#include <limits.h>
39#include <qtexttable.h>
40#include <qvariant.h>
41
43
44static inline bool shouldEnableInputMethod(QTextEdit *textedit)
45{
46#if defined (Q_OS_ANDROID)
47 return !textedit->isReadOnly() || (textedit->textInteractionFlags() & Qt::TextSelectableByMouse);
48#else
49 return !textedit->isReadOnly();
50#endif
51}
52
54{
55public:
57
58 virtual QMimeData *createMimeDataFromSelection() const override {
59 QTextEdit *ed = qobject_cast<QTextEdit *>(parent());
60 if (!ed)
62 return ed->createMimeDataFromSelection();
63 }
64 virtual bool canInsertFromMimeData(const QMimeData *source) const override {
65 QTextEdit *ed = qobject_cast<QTextEdit *>(parent());
66 if (!ed)
68 return ed->canInsertFromMimeData(source);
69 }
70 virtual void insertFromMimeData(const QMimeData *source) override {
71 QTextEdit *ed = qobject_cast<QTextEdit *>(parent());
72 if (!ed)
74 else
75 ed->insertFromMimeData(source);
76 }
77 QVariant loadResource(int type, const QUrl &name) override {
78 auto *ed = qobject_cast<QTextEdit *>(parent());
79 if (!ed)
81
82 QUrl resolvedName = ed->d_func()->resolveUrl(name);
83 return ed->loadResource(type, resolvedName);
84 }
85};
86
88 : control(nullptr),
89 autoFormatting(QTextEdit::AutoNone), tabChangesFocus(false),
90 lineWrap(QTextEdit::WidgetWidth), lineWrapColumnOrWidth(0),
91 wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), clickCausedFocus(0)
92{
94 preferRichText = false;
96 inDrag = false;
97}
98
104
106{
108 cursor.beginEditBlock();
109
110 QTextBlockFormat blockFmt = cursor.blockFormat();
111
112 QTextListFormat listFmt;
114 listFmt.setIndent(blockFmt.indent() + 1);
115
116 blockFmt.setIndent(0);
117 cursor.setBlockFormat(blockFmt);
118
119 cursor.createList(listFmt);
120
121 cursor.endEditBlock();
123}
124
126{
127 Q_Q(QTextEdit);
129 control->setPalette(q->palette());
130
131 connections = {
143 q, [q]() { q->updateMicroFocus(); }),
157 q, [q]() { q->updateMicroFocus(); }),
158 };
159
161 // set a null page size initially to avoid any relayouting until the textedit
162 // is shown. relayoutDocument() will take care of setting the page size to the
163 // viewport dimensions later.
164 doc->setPageSize(QSize(0, 0));
166 doc->setDefaultFont(q->font());
167 doc->setUndoRedoEnabled(false); // flush undo buffer.
168 doc->setUndoRedoEnabled(true);
169
170 if (!html.isEmpty())
171 control->setHtml(html);
172
173 hbar->setSingleStep(20);
174 vbar->setSingleStep(20);
175
176 viewport->setBackgroundRole(QPalette::Base);
177 q->setMouseTracking(true);
178 q->setAcceptDrops(true);
179 q->setFocusPolicy(Qt::StrongFocus);
180 q->setAttribute(Qt::WA_KeyCompression);
181 q->setAttribute(Qt::WA_InputMethodEnabled);
182 q->setInputMethodHints(Qt::ImhMultiLine);
183#ifndef QT_NO_CURSOR
184 viewport->setCursor(Qt::IBeamCursor);
185#endif
186}
187
189{
190 if (!contentsRect.isValid()) {
191 viewport->update();
192 return;
193 }
194 const int xOffset = horizontalOffset();
195 const int yOffset = verticalOffset();
196 const QRectF visibleRect(xOffset, yOffset, viewport->width(), viewport->height());
197
198 QRect r = contentsRect.intersected(visibleRect).toAlignedRect();
199 if (r.isEmpty())
200 return;
201
202 r.translate(-xOffset, -yOffset);
203 viewport->update(r);
204}
205
207{
208 Q_Q(QTextEdit);
209 emit q->cursorPositionChanged();
210#if QT_CONFIG(accessibility)
211 QAccessibleTextCursorEvent event(q, q->textCursor().position());
212 QAccessible::updateAccessibility(&event);
213#endif
214}
215
217{
218#if QT_CONFIG(cursor)
219 Q_Q(QTextEdit);
221 if (block.isValid() && !q->isReadOnly()) {
224 if (viewport->cursor().shape() != Qt::PointingHandCursor)
225 cursorToRestoreAfterHover = viewport->cursor().shape();
227 }
228 }
229 viewport->setCursor(cursor);
230#endif
231}
232
234{
236 bool moved = false;
237 qreal lastY = control->cursorRect(cursor).top();
238 qreal distance = 0;
239 // move using movePosition to keep the cursor's x
240 do {
242 distance += qAbs(y - lastY);
243 lastY = y;
244 moved = cursor.movePosition(op, moveMode);
245 } while (moved && distance < viewport->height());
246
247 if (moved) {
248 if (op == QTextCursor::Up) {
249 cursor.movePosition(QTextCursor::Down, moveMode);
250 vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
251 } else {
252 cursor.movePosition(QTextCursor::Up, moveMode);
253 vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
254 }
255 }
257}
258
259#if QT_CONFIG(scrollbar)
260static QSize documentSize(QWidgetTextControl *control)
261{
262 QTextDocument *doc = control->document();
264
265 QSize docSize;
266
267 if (QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout)) {
268 docSize = tlayout->dynamicDocumentSize().toSize();
269 int percentageDone = tlayout->layoutStatus();
270 // extrapolate height
271 if (percentageDone > 0)
272 docSize.setHeight(docSize.height() * 100 / percentageDone);
273 } else {
274 docSize = layout->documentSize().toSize();
275 }
276
277 return docSize;
278}
279
281{
283 return;
284 ignoreAutomaticScrollbarAdjustment = true; // avoid recursion, #106108
285
286 QSize viewportSize = viewport->size();
287 QSize docSize = documentSize(control);
288
289 // due to the recursion guard we have to repeat this step a few times,
290 // as adding/removing a scroll bar will cause the document or viewport
291 // size to change
292 // ideally we should loop until the viewport size and doc size stabilize,
293 // but in corner cases they might fluctuate, so we need to limit the
294 // number of iterations
295 for (int i = 0; i < 4; ++i) {
296 hbar->setRange(0, docSize.width() - viewportSize.width());
297 hbar->setPageStep(viewportSize.width());
298
299 vbar->setRange(0, docSize.height() - viewportSize.height());
300 vbar->setPageStep(viewportSize.height());
301
302 // if we are in left-to-right mode widening the document due to
303 // lazy layouting does not require a repaint. If in right-to-left
304 // the scroll bar has the value zero and it visually has the maximum
305 // value (it is visually at the right), then widening the document
306 // keeps it at value zero but visually adjusts it to the new maximum
307 // on the right, hence we need an update.
308 if (q_func()->isRightToLeft())
309 viewport->update();
310
311 _q_showOrHideScrollBars();
312
313 const QSize oldViewportSize = viewportSize;
314 const QSize oldDocSize = docSize;
315
316 // make sure the document is layouted if the viewport width changes
317 viewportSize = viewport->size();
318 if (viewportSize.width() != oldViewportSize.width())
320
321 docSize = documentSize(control);
322 if (viewportSize == oldViewportSize && docSize == oldDocSize)
323 break;
324 }
326}
327#endif
328
329// rect is in content coordinates
331{
332 const QRect rect = _rect.toRect();
333 if ((vbar->isVisible() && vbar->maximum() < rect.bottom())
334 || (hbar->isVisible() && hbar->maximum() < rect.right()))
336 const int visibleWidth = viewport->width();
337 const int visibleHeight = viewport->height();
338 const bool rtl = q_func()->isRightToLeft();
339
340 if (rect.x() < horizontalOffset()) {
341 if (rtl)
342 hbar->setValue(hbar->maximum() - rect.x());
343 else
344 hbar->setValue(rect.x());
345 } else if (rect.x() + rect.width() > horizontalOffset() + visibleWidth) {
346 if (rtl)
347 hbar->setValue(hbar->maximum() - (rect.x() + rect.width() - visibleWidth));
348 else
349 hbar->setValue(rect.x() + rect.width() - visibleWidth);
350 }
351
352 if (rect.y() < verticalOffset())
353 vbar->setValue(rect.y());
354 else if (rect.y() + rect.height() > verticalOffset() + visibleHeight)
355 vbar->setValue(rect.y() + rect.height() - visibleHeight);
356}
357
617 : QAbstractScrollArea(*new QTextEditPrivate, parent)
618{
619 Q_D(QTextEdit);
620 d->init();
621}
622
627 : QAbstractScrollArea(dd, parent)
628{
629 Q_D(QTextEdit);
630 d->init();
631}
632
638 : QAbstractScrollArea(*new QTextEditPrivate, parent)
639{
640 Q_D(QTextEdit);
641 d->init(text);
642}
643
644
645
652
659{
660 Q_D(const QTextEdit);
661 return d->control->textCursor().charFormat().fontPointSize();
662}
663
670{
671 Q_D(const QTextEdit);
672 return d->control->textCursor().charFormat().fontFamilies().toStringList().value(0, QString());
673}
674
681{
682 Q_D(const QTextEdit);
683 return d->control->textCursor().charFormat().fontWeight();
684}
685
693{
694 Q_D(const QTextEdit);
695 return d->control->textCursor().charFormat().fontUnderline();
696}
697
705{
706 Q_D(const QTextEdit);
707 return d->control->textCursor().charFormat().fontItalic();
708}
709
716{
717 Q_D(const QTextEdit);
718 return d->control->textCursor().charFormat().foreground().color();
719}
720
729{
730 Q_D(const QTextEdit);
731 const QBrush &brush = d->control->textCursor().charFormat().background();
732 return brush.style() == Qt::NoBrush ? Qt::transparent : brush.color();
733}
734
741{
742 Q_D(const QTextEdit);
743 return d->control->textCursor().charFormat().font();
744}
745
752void QTextEdit::setAlignment(Qt::Alignment a)
753{
754 Q_D(QTextEdit);
757 QTextCursor cursor = d->control->textCursor();
758 cursor.mergeBlockFormat(fmt);
759 d->control->setTextCursor(cursor);
760 d->relayoutDocument();
761}
762
768Qt::Alignment QTextEdit::alignment() const
769{
770 Q_D(const QTextEdit);
771 return d->control->textCursor().blockFormat().alignment();
772}
773
784{
785 Q_D(QTextEdit);
786 d->control->setDocument(document);
787 d->updateDefaultTextOption();
788 d->relayoutDocument();
789}
790
792{
793 Q_D(const QTextEdit);
794 return d->control->document();
795}
796
811{
812 Q_D(const QTextEdit);
813 return d->placeholderText;
814}
815
816void QTextEdit::setPlaceholderText(const QString &placeholderText)
817{
818 Q_D(QTextEdit);
819 if (d->placeholderText != placeholderText) {
820 d->placeholderText = placeholderText;
821 if (d->control->document()->isEmpty())
822 d->viewport->update();
823 }
824}
825
833
841{
842 Q_D(QTextEdit);
843 d->control->setTextCursor(cursor);
844}
845
852{
853 Q_D(const QTextEdit);
854 return d->control->textCursor();
855}
856
868
883
899
906void QTextEdit::setFontUnderline(bool underline)
907{
909 fmt.setFontUnderline(underline);
911}
912
920{
922 fmt.setFontItalic(italic);
924}
925
937
951
963
975{
976 Q_D(QTextEdit);
977 d->control->undo();
978}
979
981{
982 Q_D(QTextEdit);
983 d->control->redo();
984}
985
998#ifndef QT_NO_CLIPBOARD
1009{
1010 Q_D(QTextEdit);
1011 d->control->cut();
1012}
1013
1021{
1022 Q_D(QTextEdit);
1023 d->control->copy();
1024}
1025
1041{
1042 Q_D(QTextEdit);
1043 d->control->paste();
1044}
1045#endif
1046
1060{
1061 Q_D(QTextEdit);
1062 // clears and sets empty content
1063 d->control->clear();
1064}
1065
1066
1073{
1074 Q_D(QTextEdit);
1075 d->control->selectAll();
1076}
1077
1081{
1082 Q_D(QTextEdit);
1083 switch (e->type()) {
1085 case QEvent::ToolTip:
1086 d->sendControlEvent(e);
1087 break;
1090 d->control->setPalette(palette());
1091 break;
1092#ifndef QT_NO_CONTEXTMENU
1094 if (static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) {
1096 const QPoint cursorPos = cursorRect().center();
1097 QContextMenuEvent ce(QContextMenuEvent::Keyboard, cursorPos, d->viewport->mapToGlobal(cursorPos));
1098 ce.setAccepted(e->isAccepted());
1099 const bool result = QAbstractScrollArea::event(&ce);
1100 e->setAccepted(ce.isAccepted());
1101 return result;
1102 }
1103 break;
1104#endif // QT_NO_CONTEXTMENU
1105#ifdef QT_KEYPAD_NAVIGATION
1106 case QEvent::EnterEditFocus:
1107 case QEvent::LeaveEditFocus:
1108 if (QApplicationPrivate::keypadNavigationEnabled())
1109 d->sendControlEvent(e);
1110 break;
1111#endif
1112 default:
1113 break;
1114 }
1115 return QAbstractScrollArea::event(e);
1116}
1117
1122{
1123 Q_D(QTextEdit);
1124 if (e->timerId() == d->autoScrollTimer.timerId()) {
1125 QRect visible = d->viewport->rect();
1126 QPoint pos;
1127 if (d->inDrag) {
1128 pos = d->autoScrollDragPos;
1129 visible.adjust(qMin(visible.width()/3,20), qMin(visible.height()/3,20),
1130 -qMin(visible.width()/3,20), -qMin(visible.height()/3,20));
1131 } else {
1132 const QPoint globalPos = QCursor::pos();
1133 pos = d->viewport->mapFromGlobal(globalPos);
1134 QMouseEvent ev(QEvent::MouseMove, pos, mapTo(topLevelWidget(), pos), globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
1135 mouseMoveEvent(&ev);
1136 }
1137 int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height();
1138 int deltaX = qMax(pos.x() - visible.left(), visible.right() - pos.x()) - visible.width();
1139 int delta = qMax(deltaX, deltaY);
1140 if (delta >= 0) {
1141 if (delta < 7)
1142 delta = 7;
1143 int timeout = 4900 / (delta * delta);
1144 d->autoScrollTimer.start(timeout, this);
1145
1146 if (deltaY > 0)
1147 d->vbar->triggerAction(pos.y() < visible.center().y() ?
1150 if (deltaX > 0)
1151 d->hbar->triggerAction(pos.x() < visible.center().x() ?
1154 }
1155 }
1156#ifdef QT_KEYPAD_NAVIGATION
1157 else if (e->timerId() == d->deleteAllTimer.timerId()) {
1158 d->deleteAllTimer.stop();
1159 clear();
1160 }
1161#endif
1162}
1163
1180{
1181 Q_D(QTextEdit);
1182 d->control->setPlainText(text);
1183 d->preferRichText = false;
1184}
1185
1194{
1195 Q_D(const QTextEdit);
1196 return d->control->toPlainText();
1197}
1198
1221#ifndef QT_NO_TEXTHTMLPARSER
1223{
1224 Q_D(QTextEdit);
1225 d->control->setHtml(text);
1226 d->preferRichText = true;
1227}
1228
1230{
1231 Q_D(const QTextEdit);
1232 return d->control->toHtml();
1233}
1234#endif
1235
1236#if QT_CONFIG(textmarkdownreader) && QT_CONFIG(textmarkdownwriter)
1270#endif
1271
1272#if QT_CONFIG(textmarkdownreader)
1273void QTextEdit::setMarkdown(const QString &markdown)
1274{
1275 Q_D(const QTextEdit);
1276 d->control->setMarkdown(markdown);
1277}
1278#endif
1279
1280#if QT_CONFIG(textmarkdownwriter)
1281QString QTextEdit::toMarkdown(QTextDocument::MarkdownFeatures features) const
1282{
1283 Q_D(const QTextEdit);
1284 return d->control->toMarkdown(features);
1285}
1286#endif
1287
1291{
1292 Q_D(QTextEdit);
1293
1294#ifdef QT_KEYPAD_NAVIGATION
1295 switch (e->key()) {
1296 case Qt::Key_Select:
1297 if (QApplicationPrivate::keypadNavigationEnabled()) {
1298 // code assumes linksaccessible + editable isn't meaningful
1299 if (d->control->textInteractionFlags() & Qt::TextEditable) {
1300 setEditFocus(!hasEditFocus());
1301 } else {
1302 if (!hasEditFocus())
1303 setEditFocus(true);
1304 else {
1305 QTextCursor cursor = d->control->textCursor();
1306 QTextCharFormat charFmt = cursor.charFormat();
1307 if (!(d->control->textInteractionFlags() & Qt::LinksAccessibleByKeyboard)
1308 || !cursor.hasSelection() || charFmt.anchorHref().isEmpty()) {
1309 e->accept();
1310 return;
1311 }
1312 }
1313 }
1314 }
1315 break;
1316 case Qt::Key_Back:
1317 case Qt::Key_No:
1318 if (!QApplicationPrivate::keypadNavigationEnabled()
1319 || (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())) {
1320 e->ignore();
1321 return;
1322 }
1323 break;
1324 default:
1325 if (QApplicationPrivate::keypadNavigationEnabled()) {
1326 if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) {
1327 if (e->text()[0].isPrint())
1328 setEditFocus(true);
1329 else {
1330 e->ignore();
1331 return;
1332 }
1333 }
1334 }
1335 break;
1336 }
1337#endif
1338#ifndef QT_NO_SHORTCUT
1339
1340 Qt::TextInteractionFlags tif = d->control->textInteractionFlags();
1341
1344 e->accept();
1346 return;
1347 } else if (e ==QKeySequence::SelectNextPage) {
1348 e->accept();
1350 return;
1351 }
1352 }
1355 e->accept();
1357 return;
1358 } else if (e == QKeySequence::MoveToNextPage) {
1359 e->accept();
1361 return;
1362 }
1363 }
1364
1365 if (!(tif & Qt::TextEditable)) {
1366 switch (e->key()) {
1367 case Qt::Key_Space:
1368 e->accept();
1369 if (e->modifiers() & Qt::ShiftModifier)
1370 d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
1371 else
1372 d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
1373 break;
1374 default:
1375 d->sendControlEvent(e);
1376 if (!e->isAccepted() && e->modifiers() == Qt::NoModifier) {
1377 if (e->key() == Qt::Key_Home) {
1378 d->vbar->triggerAction(QAbstractSlider::SliderToMinimum);
1379 e->accept();
1380 } else if (e->key() == Qt::Key_End) {
1381 d->vbar->triggerAction(QAbstractSlider::SliderToMaximum);
1382 e->accept();
1383 }
1384 }
1385 if (!e->isAccepted()) {
1386 QAbstractScrollArea::keyPressEvent(e);
1387 }
1388 }
1389 return;
1390 }
1391#endif // QT_NO_SHORTCUT
1392
1393 {
1394 QTextCursor cursor = d->control->textCursor();
1395 const QString text = e->text();
1396 if (cursor.atBlockStart()
1397 && (d->autoFormatting & AutoBulletList)
1398 && (text.size() == 1)
1399 && (text.at(0) == u'-' || text.at(0) == u'*')
1400 && (!cursor.currentList())) {
1401
1402 d->createAutoBulletList();
1403 e->accept();
1404 return;
1405 }
1406 }
1407
1408 d->sendControlEvent(e);
1409#ifdef QT_KEYPAD_NAVIGATION
1410 if (!e->isAccepted()) {
1411 switch (e->key()) {
1412 case Qt::Key_Up:
1413 case Qt::Key_Down:
1414 if (QApplicationPrivate::keypadNavigationEnabled()) {
1415 // Cursor position didn't change, so we want to leave
1416 // these keys to change focus.
1417 e->ignore();
1418 return;
1419 }
1420 break;
1421 case Qt::Key_Back:
1422 if (!e->isAutoRepeat()) {
1423 if (QApplicationPrivate::keypadNavigationEnabled()) {
1424 if (document()->isEmpty() || !(d->control->textInteractionFlags() & Qt::TextEditable)) {
1425 setEditFocus(false);
1426 e->accept();
1427 } else if (!d->deleteAllTimer.isActive()) {
1428 e->accept();
1429 d->deleteAllTimer.start(750, this);
1430 }
1431 } else {
1432 e->ignore();
1433 return;
1434 }
1435 }
1436 break;
1437 default: break;
1438 }
1439 }
1440#endif
1441}
1442
1446{
1447 Q_D(QTextEdit);
1448 if (!isReadOnly())
1449 d->handleSoftwareInputPanel();
1450#ifdef QT_KEYPAD_NAVIGATION
1451 if (QApplicationPrivate::keypadNavigationEnabled()) {
1452 if (!e->isAutoRepeat() && e->key() == Qt::Key_Back
1453 && d->deleteAllTimer.isActive()) {
1454 d->deleteAllTimer.stop();
1455 QTextCursor cursor = d->control->textCursor();
1456 QTextBlockFormat blockFmt = cursor.blockFormat();
1457
1458 QTextList *list = cursor.currentList();
1459 if (list && cursor.atBlockStart()) {
1460 list->remove(cursor.block());
1461 } else if (cursor.atBlockStart() && blockFmt.indent() > 0) {
1462 blockFmt.setIndent(blockFmt.indent() - 1);
1463 cursor.setBlockFormat(blockFmt);
1464 } else {
1465 cursor.deletePreviousChar();
1466 }
1468 e->accept();
1469 return;
1470 }
1471 }
1472#endif
1473 e->ignore();
1474}
1475
1484{
1485 Q_UNUSED(type);
1486 Q_UNUSED(name);
1487 return QVariant();
1488}
1489
1493{
1494 Q_D(QTextEdit);
1495
1496 if (d->lineWrap == NoWrap) {
1497 QTextDocument *doc = d->control->document();
1498 QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");
1499
1500 if (!doc->pageSize().isNull()
1501 && alignmentProperty.userType() == QMetaType::Bool
1502 && !alignmentProperty.toBool()) {
1503
1504 d->adjustScrollbars();
1505 return;
1506 }
1507 }
1508
1509 if (d->lineWrap != FixedPixelWidth
1510 && e->oldSize().width() != e->size().width())
1511 d->relayoutDocument();
1512 else
1513 d->adjustScrollbars();
1514}
1515
1517{
1518 QTextDocument *doc = control->document();
1520
1521 if (QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout)) {
1523 tlayout->setFixedColumnWidth(lineWrapColumnOrWidth);
1524 else
1525 tlayout->setFixedColumnWidth(-1);
1526 }
1527
1528 QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout);
1529 QSize lastUsedSize;
1530 if (tlayout)
1531 lastUsedSize = tlayout->dynamicDocumentSize().toSize();
1532 else
1533 lastUsedSize = layout->documentSize().toSize();
1534
1535 // ignore calls to adjustScrollbars caused by an emission of the
1536 // usedSizeChanged() signal in the layout, as we're calling it
1537 // later on our own anyway (or deliberately not) .
1538 const bool oldIgnoreScrollbarAdjustment = ignoreAutomaticScrollbarAdjustment;
1540
1541 int width = viewport->width();
1544 else if (lineWrap == QTextEdit::NoWrap) {
1545 QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");
1546 if (alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) {
1547
1548 width = 0;
1549 }
1550 }
1551
1552 doc->setPageSize(QSize(width, -1));
1553 if (tlayout)
1554 tlayout->ensureLayouted(verticalOffset() + viewport->height());
1555
1556 ignoreAutomaticScrollbarAdjustment = oldIgnoreScrollbarAdjustment;
1557
1558 QSize usedSize;
1559 if (tlayout)
1560 usedSize = tlayout->dynamicDocumentSize().toSize();
1561 else
1562 usedSize = layout->documentSize().toSize();
1563
1564 // this is an obscure situation in the layout that can happen:
1565 // if a character at the end of a line is the tallest one and therefore
1566 // influencing the total height of the line and the line right below it
1567 // is always taller though, then it can happen that if due to line breaking
1568 // that tall character wraps into the lower line the document not only shrinks
1569 // horizontally (causing the character to wrap in the first place) but also
1570 // vertically, because the original line is now smaller and the one below kept
1571 // its size. So a layout with less width _can_ take up less vertical space, too.
1572 // If the wider case causes a vertical scroll bar to appear and the narrower one
1573 // (narrower because the vertical scroll bar takes up horizontal space)) to disappear
1574 // again then we have an endless loop, as adjustScrollbars sets new ranges on the
1575 // scroll bars, the QAbstractScrollArea will find out about it and try to show/hide
1576 // the scroll bars again. That's why we try to detect this case here and break out.
1577 //
1578 // (if you change this please also check the layoutingLoop() testcase in
1579 // QTextEdit's autotests)
1580 if (lastUsedSize.isValid()
1581 && !vbar->isHidden()
1582 && viewport->width() < lastUsedSize.width()
1583 && usedSize.height() < lastUsedSize.height()
1584 && usedSize.height() <= viewport->height())
1585 return;
1586
1588}
1589
1591{
1592 const int xOffset = horizontalOffset();
1593 const int yOffset = verticalOffset();
1594
1595 QRect r = e->rect();
1596 p->translate(-xOffset, -yOffset);
1597 r.translate(xOffset, yOffset);
1598
1599 QTextDocument *doc = control->document();
1600 QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(doc->documentLayout());
1601
1602 // the layout might need to expand the root frame to
1603 // the viewport if NoWrap is set
1604 if (layout)
1605 layout->setViewport(viewport->rect());
1606
1607 control->drawContents(p, r, q_func());
1608
1609 if (layout)
1610 layout->setViewport(QRect());
1611
1612 if (!placeholderText.isEmpty() && doc->isEmpty() && !control->isPreediting()) {
1613 const QColor col = control->palette().placeholderText().color();
1614 p->setPen(col);
1615 const int margin = int(doc->documentMargin());
1616 p->drawText(viewport->rect().adjusted(margin, margin, -margin, -margin), Qt::AlignTop | Qt::TextWordWrap, placeholderText);
1617 }
1618}
1619
1631{
1632 Q_D(QTextEdit);
1633 QPainter p(d->viewport);
1634 d->paint(&p, e);
1635}
1636
1638{
1639 QTextDocument *doc = control->document();
1640
1642 QTextOption::WrapMode oldWrapMode = opt.wrapMode();
1643
1645 opt.setWrapMode(QTextOption::NoWrap);
1646 else
1647 opt.setWrapMode(wordWrap);
1648
1649 if (opt.wrapMode() != oldWrapMode)
1651}
1652
1656{
1657 Q_D(QTextEdit);
1658#ifdef QT_KEYPAD_NAVIGATION
1659 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())
1660 setEditFocus(true);
1661#endif
1662 d->sendControlEvent(e);
1663}
1664
1668{
1669 Q_D(QTextEdit);
1670 d->inDrag = false; // paranoia
1671 const QPoint pos = e->position().toPoint();
1672 d->sendControlEvent(e);
1673 if (!(e->buttons() & Qt::LeftButton))
1674 return;
1676 const QRect visible = d->viewport->rect();
1677 if (visible.contains(pos))
1678 d->autoScrollTimer.stop();
1679 else if (!d->autoScrollTimer.isActive())
1680 d->autoScrollTimer.start(100, this);
1681 }
1682}
1683
1687{
1688 Q_D(QTextEdit);
1689 d->sendControlEvent(e);
1690 if (e->source() == Qt::MouseEventNotSynthesized && d->autoScrollTimer.isActive()) {
1691 d->autoScrollTimer.stop();
1693 }
1694 if (!isReadOnly() && rect().contains(e->position().toPoint()))
1695 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
1696 d->clickCausedFocus = 0;
1697}
1698
1702{
1703 Q_D(QTextEdit);
1704 d->sendControlEvent(e);
1705}
1706
1710{
1711 Q_D(const QTextEdit);
1712 if (!d->tabChangesFocus && d->control->textInteractionFlags() & Qt::TextEditable)
1713 return false;
1714 return QAbstractScrollArea::focusNextPrevChild(next);
1715}
1716
1717#ifndef QT_NO_CONTEXTMENU
1734{
1735 Q_D(QTextEdit);
1736 d->sendControlEvent(e);
1737}
1738#endif // QT_NO_CONTEXTMENU
1739
1740#if QT_CONFIG(draganddrop)
1743void QTextEdit::dragEnterEvent(QDragEnterEvent *e)
1744{
1745 Q_D(QTextEdit);
1746 d->inDrag = true;
1747 d->sendControlEvent(e);
1748}
1749
1752void QTextEdit::dragLeaveEvent(QDragLeaveEvent *e)
1753{
1754 Q_D(QTextEdit);
1755 d->inDrag = false;
1756 d->autoScrollTimer.stop();
1757 d->sendControlEvent(e);
1758}
1759
1762void QTextEdit::dragMoveEvent(QDragMoveEvent *e)
1763{
1764 Q_D(QTextEdit);
1765 d->autoScrollDragPos = e->position().toPoint();
1766 if (!d->autoScrollTimer.isActive())
1767 d->autoScrollTimer.start(100, this);
1768 d->sendControlEvent(e);
1769}
1770
1773void QTextEdit::dropEvent(QDropEvent *e)
1774{
1775 Q_D(QTextEdit);
1776 d->inDrag = false;
1777 d->autoScrollTimer.stop();
1778 d->sendControlEvent(e);
1779}
1780
1781#endif // QT_CONFIG(draganddrop)
1782
1786{
1787 Q_D(QTextEdit);
1788#ifdef QT_KEYPAD_NAVIGATION
1789 if (d->control->textInteractionFlags() & Qt::TextEditable
1790 && QApplicationPrivate::keypadNavigationEnabled()
1791 && !hasEditFocus())
1792 setEditFocus(true);
1793#endif
1794 d->sendControlEvent(e);
1795 const bool emptyEvent = e->preeditString().isEmpty() && e->commitString().isEmpty()
1796 && e->attributes().isEmpty();
1797 if (emptyEvent)
1798 return;
1800}
1801
1805{
1806 Q_D(QTextEdit);
1807 if (isRightToLeft())
1808 dx = -dx;
1809 d->viewport->scroll(dx, dy);
1811}
1812
1819
1823{
1824 Q_D(const QTextEdit);
1825 switch (query) {
1826 case Qt::ImEnabled:
1827 return isEnabled() && !isReadOnly();
1828 case Qt::ImHints:
1831 case Qt::ImReadOnly:
1832 return isReadOnly();
1833 default:
1834 break;
1835 }
1836
1837 const QPointF offset(-d->horizontalOffset(), -d->verticalOffset());
1838 switch (argument.userType()) {
1839 case QMetaType::QRectF:
1840 argument = argument.toRectF().translated(-offset);
1841 break;
1842 case QMetaType::QPointF:
1843 argument = argument.toPointF() - offset;
1844 break;
1845 case QMetaType::QRect:
1846 argument = argument.toRect().translated(-offset.toPoint());
1847 break;
1848 case QMetaType::QPoint:
1849 argument = argument.toPoint() - offset;
1850 break;
1851 default:
1852 break;
1853 }
1854
1855 const QVariant v = d->control->inputMethodQuery(query, argument);
1856 switch (v.userType()) {
1857 case QMetaType::QRectF:
1858 return v.toRectF().translated(offset);
1859 case QMetaType::QPointF:
1860 return v.toPointF() + offset;
1861 case QMetaType::QRect:
1862 return v.toRect().translated(offset.toPoint());
1863 case QMetaType::QPoint:
1864 return v.toPoint() + offset.toPoint();
1865 default:
1866 break;
1867 }
1868 return v;
1869}
1870
1874{
1875 Q_D(QTextEdit);
1876 if (e->reason() == Qt::MouseFocusReason) {
1877 d->clickCausedFocus = 1;
1878 }
1879 QAbstractScrollArea::focusInEvent(e);
1880 d->sendControlEvent(e);
1881}
1882
1886{
1887 Q_D(QTextEdit);
1888 QAbstractScrollArea::focusOutEvent(e);
1889 d->sendControlEvent(e);
1890}
1891
1895{
1896 Q_D(QTextEdit);
1897 if (!d->anchorToScrollToWhenVisible.isEmpty()) {
1898 scrollToAnchor(d->anchorToScrollToWhenVisible);
1899 d->anchorToScrollToWhenVisible.clear();
1900 d->showCursorOnInitialShow = false;
1901 } else if (d->showCursorOnInitialShow) {
1902 d->showCursorOnInitialShow = false;
1904 }
1905}
1906
1910{
1911 Q_D(QTextEdit);
1912 QAbstractScrollArea::changeEvent(e);
1914 || e->type() == QEvent::FontChange) {
1915 d->control->document()->setDefaultFont(font());
1916 } else if (e->type() == QEvent::ActivationChange) {
1917 if (!isActiveWindow())
1918 d->autoScrollTimer.stop();
1919 } else if (e->type() == QEvent::EnabledChange) {
1920 e->setAccepted(isEnabled());
1921 d->control->setPalette(palette());
1922 d->sendControlEvent(e);
1923 } else if (e->type() == QEvent::PaletteChange) {
1924 d->control->setPalette(palette());
1925 } else if (e->type() == QEvent::LayoutDirectionChange) {
1926 d->sendControlEvent(e);
1927 }
1928}
1929
1932#if QT_CONFIG(wheelevent)
1933void QTextEdit::wheelEvent(QWheelEvent *e)
1934{
1935 Q_D(QTextEdit);
1936 if (!(d->control->textInteractionFlags() & Qt::TextEditable)) {
1937 if (e->modifiers() & Qt::ControlModifier) {
1938 float delta = e->angleDelta().y() / 120.f;
1939 zoomInF(delta);
1940 return;
1941 }
1942 }
1943 QAbstractScrollArea::wheelEvent(e);
1944 updateMicroFocus();
1945}
1946#endif
1947
1948#ifndef QT_NO_CONTEXTMENU
1959{
1960 Q_D(QTextEdit);
1961 return d->control->createStandardContextMenu(QPointF(), this);
1962}
1963
1975{
1976 Q_D(QTextEdit);
1977 return d->control->createStandardContextMenu(position, this);
1978}
1979#endif // QT_NO_CONTEXTMENU
1980
1985{
1986 Q_D(const QTextEdit);
1987 return d->control->cursorForPosition(d->mapToContents(pos));
1988}
1989
1995{
1996 Q_D(const QTextEdit);
1997 if (cursor.isNull())
1998 return QRect();
1999
2000 QRect r = d->control->cursorRect(cursor).toRect();
2001 r.translate(-d->horizontalOffset(),-d->verticalOffset());
2002 return r;
2003}
2004
2010{
2011 Q_D(const QTextEdit);
2012 QRect r = d->control->cursorRect().toRect();
2013 r.translate(-d->horizontalOffset(),-d->verticalOffset());
2014 return r;
2015}
2016
2017
2023{
2024 Q_D(const QTextEdit);
2025 return d->control->anchorAt(d->mapToContents(pos));
2026}
2027
2044{
2045 Q_D(const QTextEdit);
2046 return d->control->overwriteMode();
2047}
2048
2050{
2051 Q_D(QTextEdit);
2052 d->control->setOverwriteMode(overwrite);
2053}
2054
2070{
2071 Q_D(const QTextEdit);
2072 return d->control->document()->defaultTextOption().tabStopDistance();
2073}
2074
2076{
2077 Q_D(QTextEdit);
2078 QTextOption opt = d->control->document()->defaultTextOption();
2079 if (opt.tabStopDistance() == distance || distance < 0)
2080 return;
2081 opt.setTabStopDistance(distance);
2082 d->control->document()->setDefaultTextOption(opt);
2083}
2084
2092{
2093 Q_D(const QTextEdit);
2094 return d->control->cursorWidth();
2095}
2096
2098{
2099 Q_D(QTextEdit);
2100 d->control->setCursorWidth(width);
2101}
2102
2115{
2116 Q_D(const QTextEdit);
2117 return d->control->acceptRichText();
2118}
2119
2121{
2122 Q_D(QTextEdit);
2123 d->control->setAcceptRichText(accept);
2124}
2125
2155void QTextEdit::setExtraSelections(const QList<ExtraSelection> &selections)
2156{
2157 Q_D(QTextEdit);
2158 d->control->setExtraSelections(selections);
2159}
2160
2167QList<QTextEdit::ExtraSelection> QTextEdit::extraSelections() const
2168{
2169 Q_D(const QTextEdit);
2170 return d->control->extraSelections();
2171}
2172
2184{
2185 Q_D(const QTextEdit);
2186 return d->control->QWidgetTextControl::createMimeDataFromSelection();
2187}
2188
2199{
2200 Q_D(const QTextEdit);
2201 return d->control->QWidgetTextControl::canInsertFromMimeData(source);
2202}
2203
2214{
2215 Q_D(QTextEdit);
2216 d->control->QWidgetTextControl::insertFromMimeData(source);
2217}
2218
2230{
2231 Q_D(const QTextEdit);
2232 return !d->control || !(d->control->textInteractionFlags() & Qt::TextEditable);
2233}
2234
2236{
2237 Q_D(QTextEdit);
2238 Qt::TextInteractionFlags flags = Qt::NoTextInteraction;
2239 if (ro) {
2241#if QT_CONFIG(textbrowser)
2242 if (qobject_cast<QTextBrowser *>(this))
2244#endif
2245 } else {
2247 }
2248 d->control->setTextInteractionFlags(flags);
2252}
2253
2264void QTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags)
2265{
2266 Q_D(QTextEdit);
2267 d->control->setTextInteractionFlags(flags);
2268}
2269
2270Qt::TextInteractionFlags QTextEdit::textInteractionFlags() const
2271{
2272 Q_D(const QTextEdit);
2273 return d->control->textInteractionFlags();
2274}
2275
2285{
2286 Q_D(QTextEdit);
2287 d->control->mergeCurrentCharFormat(modifier);
2288}
2289
2297{
2298 Q_D(QTextEdit);
2299 d->control->setCurrentCharFormat(format);
2300}
2301
2306{
2307 Q_D(const QTextEdit);
2308 return d->control->currentCharFormat();
2309}
2310
2323QTextEdit::AutoFormatting QTextEdit::autoFormatting() const
2324{
2325 Q_D(const QTextEdit);
2326 return d->autoFormatting;
2327}
2328
2329void QTextEdit::setAutoFormatting(AutoFormatting features)
2330{
2331 Q_D(QTextEdit);
2332 d->autoFormatting = features;
2333}
2334
2344{
2345 Q_D(QTextEdit);
2346 d->control->insertPlainText(text);
2347}
2348
2362#ifndef QT_NO_TEXTHTMLPARSER
2364{
2365 Q_D(QTextEdit);
2366 d->control->insertHtml(text);
2367}
2368#endif // QT_NO_TEXTHTMLPARSER
2369
2376{
2377 Q_D(QTextEdit);
2378 if (name.isEmpty())
2379 return;
2380
2381 if (!isVisible()) {
2382 d->anchorToScrollToWhenVisible = name;
2383 return;
2384 }
2385
2386 QPointF p = d->control->anchorPosition(name);
2387 const int newPosition = qRound(p.y());
2388 if ( d->vbar->maximum() < newPosition )
2389 d->adjustScrollbars();
2390 d->vbar->setValue(newPosition);
2391}
2392
2401{
2402 zoomInF(range);
2403}
2404
2413{
2414 zoomInF(-range);
2415}
2416
2421{
2422 if (range == 0.f)
2423 return;
2424 QFont f = font();
2425 const float newSize = f.pointSizeF() + range;
2426 if (newSize <= 0)
2427 return;
2428 f.setPointSizeF(newSize);
2429 setFont(f);
2430}
2431
2443{
2444 Q_D(QTextEdit);
2445 d->control->moveCursor(operation, mode);
2446}
2447
2453{
2454 Q_D(const QTextEdit);
2455 return d->control->canPaste();
2456}
2457
2466#ifndef QT_NO_PRINTER
2468{
2469 Q_D(const QTextEdit);
2470 d->control->print(printer);
2471}
2472#endif
2473
2484{
2485 Q_D(const QTextEdit);
2486 return d->tabChangesFocus;
2487}
2488
2490{
2491 Q_D(QTextEdit);
2492 d->tabChangesFocus = b;
2493}
2494
2518{
2519 Q_D(const QTextEdit);
2520 return d->lineWrap;
2521}
2522
2524{
2525 Q_D(QTextEdit);
2526 if (d->lineWrap == wrap)
2527 return;
2528 d->lineWrap = wrap;
2529 d->updateDefaultTextOption();
2530 d->relayoutDocument();
2531}
2532
2549{
2550 Q_D(const QTextEdit);
2551 return d->lineWrapColumnOrWidth;
2552}
2553
2555{
2556 Q_D(QTextEdit);
2557 d->lineWrapColumnOrWidth = w;
2558 d->relayoutDocument();
2559}
2560
2571{
2572 Q_D(const QTextEdit);
2573 return d->wordWrap;
2574}
2575
2577{
2578 Q_D(QTextEdit);
2579 if (mode == d->wordWrap)
2580 return;
2581 d->wordWrap = mode;
2582 d->updateDefaultTextOption();
2583}
2584
2590bool QTextEdit::find(const QString &exp, QTextDocument::FindFlags options)
2591{
2592 Q_D(QTextEdit);
2593 return d->control->find(exp, options);
2594}
2595
2612#if QT_CONFIG(regularexpression)
2613bool QTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options)
2614{
2615 Q_D(QTextEdit);
2616 return d->control->find(exp, options);
2617}
2618#endif
2619
2673{
2675#ifndef QT_NO_TEXTHTMLPARSER
2676 if (format == Qt::RichText)
2677 setHtml(text);
2678 else
2679#else
2681#endif
2683}
2684
2685
2696{
2697 Q_D(QTextEdit);
2698 const bool atBottom = isReadOnly() ? d->verticalOffset() >= d->vbar->maximum() :
2699 d->control->textCursor().atEnd();
2700 d->control->append(text);
2701 if (atBottom)
2702 d->vbar->setValue(d->vbar->maximum());
2703}
2704
2710{
2711 Q_D(QTextEdit);
2712 d->control->ensureCursorVisible();
2713}
2714
2737
2738#include "moc_qtextedit.cpp"
void setPaintDevice(QPaintDevice *device)
Sets the paint device used for rendering the document's layout to the given device.
\inmodule QtGui
Definition qbrush.h:30
const QColor & color() const
Returns the brush color.
Definition qbrush.h:121
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:594
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
Definition qcursor.cpp:188
\inmodule QtCore
Definition qcoreevent.h:45
virtual void setAccepted(bool accepted)
Definition qcoreevent.h:307
@ EnabledChange
Definition qcoreevent.h:134
@ LayoutDirectionChange
Definition qcoreevent.h:124
@ ReadOnlyChange
Definition qcoreevent.h:145
@ ShortcutOverride
Definition qcoreevent.h:158
@ FontChange
Definition qcoreevent.h:133
@ MouseMove
Definition qcoreevent.h:63
@ ActivationChange
Definition qcoreevent.h:135
@ WindowActivate
Definition qcoreevent.h:83
@ PaletteChange
Definition qcoreevent.h:94
@ ApplicationFontChange
Definition qcoreevent.h:91
@ WindowDeactivate
Definition qcoreevent.h:84
@ ContextMenu
Definition qcoreevent.h:119
Type type() const
Returns the event type.
Definition qcoreevent.h:304
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
bool isAccepted() const
Definition qcoreevent.h:308
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:310
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
Qt::FocusReason reason() const
Returns the reason for this focus event.
Definition qevent.cpp:1569
\reentrant
Definition qfont.h:22
static QInputMethod * inputMethod()
returns the input method.
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:625
const QString & preeditString() const
Returns the preedit text, i.e.
Definition qevent.h:650
const QString & commitString() const
Returns the text that should get added to (or replace parts of) the text of the editor widget.
Definition qevent.h:652
const QList< Attribute > & attributes() const
Returns the list of attributes passed to the QInputMethodEvent constructor.
Definition qevent.h:649
The QKeyEvent class describes a key event.
Definition qevent.h:424
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1468
QString text() const
Returns the Unicode text that this key generated.
Definition qevent.h:443
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
Definition qevent.h:444
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:434
void remove(qsizetype i, qsizetype n=1)
Definition qlist.h:794
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
\inmodule QtCore Represents a handle to a signal-slot (or signal-functor) connection.
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtGui
Definition qevent.h:196
Qt::MouseEventSource source() const
Definition qevent.cpp:801
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
QVariant property(const char *name) const
Returns the value of the object's name property.
Definition qobject.cpp:4323
\inmodule QtGui
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
const QRect & rect() const
Returns the rectangle that needs to be updated.
Definition qevent.h:492
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
const QBrush & placeholderText() const
Definition qpalette.h:102
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:484
QRect toAlignedRect() const noexcept
Definition qrect.cpp:2338
constexpr QRectF translated(qreal dx, qreal dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:762
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:498
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:666
QRectF intersected(const QRectF &other) const noexcept
Definition qrect.h:847
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition qrect.h:373
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:855
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
constexpr void translate(int dx, int dy) noexcept
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
Definition qrect.h:245
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:233
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
\inmodule QtCore \reentrant
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
const QSize & oldSize() const
Returns the old size of the widget.
Definition qevent.h:554
const QSize & size() const
Returns the new size of the widget.
Definition qevent.h:553
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:578
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:119
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:116
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition qevent.h:117
bool isNull() const noexcept
Returns true if both the width and height are 0.0 (ignoring the sign); otherwise returns false.
Definition qsize.h:323
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:139
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
MarkerType marker() const
void setAlignment(Qt::Alignment alignment)
Sets the paragraph's alignment.
\reentrant
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
void setFontFamilies(const QStringList &families)
void setFontPointSize(qreal size)
Sets the text format's font size.
void setFontUnderline(bool underline)
If underline is true, sets the text format's font to be underlined; otherwise it is displayed non-und...
void setFontItalic(bool italic)
If italic is true, sets the text format's font to be italic; otherwise the font will be non-italic.
void setFontWeight(int weight)
Sets the text format's font weight to weight.
void setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior=FontPropertiesAll)
\reentrant \inmodule QtGui
Definition qtextcursor.h:30
MoveMode
\value MoveAnchor Moves the anchor to the same position as the cursor itself.
Definition qtextcursor.h:47
MoveOperation
\value NoMove Keep the cursor where it is
Definition qtextcursor.h:61
\reentrant \inmodule QtGui
bool isEmpty() const
Returns true if the document is empty; otherwise returns false.
void setDefaultTextOption(const QTextOption &option)
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
QSizeF pageSize
the page size that should be used for laying out the document
QTextOption defaultTextOption() const
the default text option will be set on all \l{QTextLayout}s in the document.
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
void setPageSize(const QSizeF &size)
void setUndoRedoEnabled(bool enable)
virtual void insertFromMimeData(const QMimeData *source) override
Definition qtextedit.cpp:70
virtual QMimeData * createMimeDataFromSelection() const override
Definition qtextedit.cpp:58
QVariant loadResource(int type, const QUrl &name) override
Definition qtextedit.cpp:77
virtual bool canInsertFromMimeData(const QMimeData *source) const override
Definition qtextedit.cpp:64
QTextEditControl(QObject *parent)
Definition qtextedit.cpp:56
QWidgetTextControl * control
Definition qtextedit_p.h:81
void repaintContents(const QRectF &contentsRect)
QTextEdit::LineWrapMode lineWrap
Definition qtextedit_p.h:89
void hoveredBlockWithMarkerChanged(const QTextBlock &block)
void pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode)
Qt::CursorShape cursorToRestoreAfterHover
int horizontalOffset() const
Definition qtextedit_p.h:64
uint ignoreAutomaticScrollbarAdjustment
Definition qtextedit_p.h:93
void ensureVisible(const QRectF &rect)
int verticalOffset() const
Definition qtextedit_p.h:66
void createAutoBulletList()
void cursorPositionChanged()
std::array< QMetaObject::Connection, 13 > connections
QString placeholderText
uint showCursorOnInitialShow
Definition qtextedit_p.h:95
void paint(QPainter *p, QPaintEvent *e)
void init(const QString &html=QString())
void adjustScrollbars()
void updateDefaultTextOption()
QTextOption::WrapMode wordWrap
Definition qtextedit_p.h:91
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
Definition qtextedit.h:27
QString toHtml() const
virtual void scrollContentsBy(int dx, int dy) override
\reimp
void ensureCursorVisible()
Ensures that the cursor is visible by scrolling the text edit if necessary.
virtual void paintEvent(QPaintEvent *e) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void redoAvailable(bool b)
This signal is emitted whenever redo operations become available (available is true) or unavailable (...
void setCursorWidth(int width)
void redo()
virtual void resizeEvent(QResizeEvent *e) override
\reimp
void paste()
Pastes the text from the clipboard into the text edit at the current cursor position.
void setTextCursor(const QTextCursor &cursor)
Sets the visible cursor.
virtual void focusInEvent(QFocusEvent *e) override
\reimp
QString placeholderText
the editor placeholder text
Definition qtextedit.h:52
void setTabChangesFocus(bool b)
qreal tabStopDistance
the tab stop distance in pixels
Definition qtextedit.h:46
void zoomIn(int range=1)
Zooms in on the text by making the base font size range points larger and recalculating all font size...
int cursorWidth
Definition qtextedit.h:48
int lineWrapColumnOrWidth
the position (in pixels or columns depending on the wrap mode) where text will be wrapped
Definition qtextedit.h:36
QString fontFamily() const
Returns the font family of the current format.
virtual void showEvent(QShowEvent *) override
\reimp
virtual void mousePressEvent(QMouseEvent *e) override
\reimp
virtual bool focusNextPrevChild(bool next) override
\reimp
LineWrapMode
\value NoWrap \value WidgetWidth \value FixedPixelWidth \value FixedColumnWidth
Definition qtextedit.h:54
@ FixedPixelWidth
Definition qtextedit.h:57
@ FixedColumnWidth
Definition qtextedit.h:58
virtual void mouseReleaseEvent(QMouseEvent *e) override
\reimp
bool find(const QString &exp, QTextDocument::FindFlags options=QTextDocument::FindFlags())
Finds the next occurrence of the string, exp, using the given options.
QVariant inputMethodQuery(Qt::InputMethodQuery property) const override
\reimp
QTextOption::WrapMode wordWrapMode() const
the mode QTextEdit will use when wrapping text by words
bool isReadOnly() const
void setTextBackgroundColor(const QColor &c)
void setTextColor(const QColor &c)
Sets the text color of the current format to c.
void setLineWrapMode(LineWrapMode mode)
void setFontUnderline(bool b)
If underline is true, sets the current format to underline; otherwise sets the current format to non-...
virtual void contextMenuEvent(QContextMenuEvent *e) override
Shows the standard context menu created with createStandardContextMenu().
void currentCharFormatChanged(const QTextCharFormat &format)
This signal is emitted if the current character format has changed, for example caused by a change of...
QMenu * createStandardContextMenu()
\reimp
void insertHtml(const QString &text)
Convenience slot that inserts text which is assumed to be of html formatting at the current cursor po...
void setReadOnly(bool ro)
void setAutoFormatting(AutoFormatting features)
void undoAvailable(bool b)
This signal is emitted whenever undo operations become available (available is true) or unavailable (...
virtual void inputMethodEvent(QInputMethodEvent *) override
\reimp
void selectAll()
Selects all text.
void append(const QString &text)
Appends a new paragraph with text to the end of the text edit.
void zoomOut(int range=1)
Zooms out on the text by making the base font size range points smaller and recalculating all font si...
void undo()
QColor textColor() const
Returns the text color of the current format.
void setText(const QString &text)
void setCurrentCharFormat(const QTextCharFormat &format)
Sets the char format that is be used when inserting new text to format by calling QTextCursor::setCha...
Qt::TextInteractionFlags textInteractionFlags
Definition qtextedit.h:50
QTextCursor cursorForPosition(const QPoint &pos) const
returns a QTextCursor at position pos (in viewport coordinates).
bool acceptRichText
whether the text edit accepts rich text insertions by the user
Definition qtextedit.h:47
void mergeCurrentCharFormat(const QTextCharFormat &modifier)
Merges the properties specified in modifier into the current character format by calling QTextCursor:...
LineWrapMode lineWrapMode
the line wrap mode
Definition qtextedit.h:34
void setLineWrapColumnOrWidth(int w)
void copyAvailable(bool b)
This signal is emitted when text is selected or de-selected in the text edit.
QTextCharFormat currentCharFormat() const
Returns the char format that is used when inserting new text.
void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode=QTextCursor::MoveAnchor)
QColor textBackgroundColor() const
bool overwriteMode
whether text entered by the user will overwrite existing text
Definition qtextedit.h:45
void textChanged()
This signal is emitted whenever the document's content changes; for example, when text is inserted or...
virtual QMimeData * createMimeDataFromSelection() const
This function returns a new MIME data object to represent the contents of the text edit's current sel...
virtual void doSetTextCursor(const QTextCursor &cursor)
bool tabChangesFocus
whether \uicontrol Tab changes focus or is accepted as input
Definition qtextedit.h:31
bool fontUnderline() const
Returns true if the font of the current format is underlined; otherwise returns false.
QTextEdit(QWidget *parent=nullptr)
Constructs an empty QTextEdit with parent parent.
void setExtraSelections(const QList< ExtraSelection > &selections)
\variable QTextEdit::ExtraSelection::cursor A cursor that contains a selection in a QTextDocument
bool canPaste() const
void copy()
Copies any selected text to the clipboard.
AutoFormatting autoFormatting
the enabled set of auto formatting features
Definition qtextedit.h:30
void setPlainText(const QString &text)
Changes the text of the text edit to the string text.
virtual void keyReleaseEvent(QKeyEvent *e) override
\reimp
QTextCursor textCursor() const
Returns a copy of the QTextCursor that represents the currently visible cursor.
QRect cursorRect() const
returns a rectangle (in viewport coordinates) that includes the cursor of the text edit.
QString anchorAt(const QPoint &pos) const
Returns the reference of the anchor at position pos, or an empty string if no anchor exists at that p...
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
void clear()
Deletes all the text in the text edit.
bool fontItalic() const
Returns true if the font of the current format is italic; otherwise returns false.
@ AutoBulletList
Definition qtextedit.h:64
qreal fontPointSize() const
Returns the point size of the font of the current format.
virtual void keyPressEvent(QKeyEvent *e) override
\reimp
void setWordWrapMode(QTextOption::WrapMode policy)
void setCurrentFont(const QFont &f)
Sets the font of the current format to f.
virtual bool canInsertFromMimeData(const QMimeData *source) const
This function returns true if the contents of the MIME data object, specified by source,...
void setAlignment(Qt::Alignment a)
Sets the alignment of the current paragraph to a.
void setPlaceholderText(const QString &placeholderText)
virtual Q_INVOKABLE QVariant loadResource(int type, const QUrl &name)
Loads the resource specified by the given type and name.
void setOverwriteMode(bool overwrite)
virtual void timerEvent(QTimerEvent *e) override
void setFontItalic(bool b)
If italic is true, sets the current format to italic; otherwise sets the current format to non-italic...
virtual ~QTextEdit()
Destructor.
virtual void mouseMoveEvent(QMouseEvent *e) override
\reimp
void setFontPointSize(qreal s)
Sets the point size of the current format to s.
void setFontFamily(const QString &fontFamily)
Sets the font family of the current format to fontFamily.
void setFontWeight(int w)
Sets the font weight of the current format to the given weight, where the value used is in the range ...
QString toPlainText() const
QString QTextEdit::toPlainText() const.
Qt::Alignment alignment() const
Returns the alignment of the current paragraph.
void setAcceptRichText(bool accept)
QFont currentFont() const
Returns the font of the current format.
virtual void insertFromMimeData(const QMimeData *source)
This function inserts the contents of the MIME data object, specified by source, into the text edit a...
void setHtml(const QString &text)
virtual void mouseDoubleClickEvent(QMouseEvent *e) override
\reimp
void insertPlainText(const QString &text)
Convenience slot that inserts text at the current cursor position.
void zoomInF(float range)
void print(QPagedPaintDevice *printer) const
void scrollToAnchor(const QString &name)
Scrolls the text edit so that the anchor with the given name is visible; does nothing if the name is ...
virtual void changeEvent(QEvent *e) override
\reimp
void setDocument(QTextDocument *document)
void setTabStopDistance(qreal distance)
int fontWeight() const
Returns the font weight of the current format.
virtual bool event(QEvent *e) override
QTextDocument * document
the underlying document of the text editor.
Definition qtextedit.h:51
void cut()
Copies the selected text to the clipboard and deletes it from the text edit.
virtual void focusOutEvent(QFocusEvent *e) override
\reimp
QList< ExtraSelection > extraSelections() const
void selectionChanged()
This signal is emitted whenever the selection changes.
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
void setBackground(const QBrush &brush)
Sets the brush use to paint the document's background to the brush specified.
void setStyle(Style style)
Sets the list format's style.
\reentrant
Definition qtextlist.h:18
\reentrant
Definition qtextoption.h:18
WrapMode
This enum describes how text is wrapped in a document.
Definition qtextoption.h:60
\inmodule QtCore
Definition qcoreevent.h:366
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition qcoreevent.h:370
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
QRectF toRectF() const
Returns the variant as a QRectF if the variant has userType() \l QMetaType::QRect or \l QMetaType::QR...
QTextCursor textCursor() const
void redoAvailable(bool b)
void setHtml(const QString &text)
void cursorPositionChanged()
virtual QMimeData * createMimeDataFromSelection() const
void setTextCursor(const QTextCursor &cursor, bool selectionClipboard=false)
virtual Q_INVOKABLE QVariant loadResource(int type, const QUrl &name)
void undoAvailable(bool b)
QRectF cursorRect(const QTextCursor &cursor) const
void updateRequest(const QRectF &rect=QRectF())
void blockMarkerHovered(const QTextBlock &block)
void drawContents(QPainter *painter, const QRectF &rect=QRectF(), QWidget *widget=nullptr)
void documentSizeChanged(const QSizeF &)
virtual void insertFromMimeData(const QMimeData *source)
void currentCharFormatChanged(const QTextCharFormat &format)
void visibilityRequest(const QRectF &rect)
virtual bool canInsertFromMimeData(const QMimeData *source) const
void setPalette(const QPalette &pal)
QTextDocument * document() const
void copyAvailable(bool b)
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition qwidget.cpp:9913
QString text
QCursor cursor
rect
[4]
QStyleOptionButton opt
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isRightToLeft(QStringView string) noexcept
InputMethodQuery
@ ImAnchorRectangle
@ ImInputItemClipRectangle
@ ImReadOnly
@ ImCursorRectangle
@ ImHints
@ ImEnabled
@ AlignTop
Definition qnamespace.h:153
@ LeftButton
Definition qnamespace.h:58
@ TextSelectableByMouse
@ TextEditable
@ TextBrowserInteraction
@ TextEditorInteraction
@ LinksAccessibleByKeyboard
@ TextSelectableByKeyboard
@ NoTextInteraction
@ WA_KeyCompression
Definition qnamespace.h:300
@ WA_InputMethodEnabled
Definition qnamespace.h:295
TextFormat
@ RichText
@ PlainText
@ StrongFocus
Definition qnamespace.h:110
@ TextWordWrap
Definition qnamespace.h:174
@ MouseEventNotSynthesized
Q_GUI_EXPORT bool mightBeRichText(QAnyStringView)
Returns true if the string text is likely to be rich text; otherwise returns false.
CursorShape
@ PointingHandCursor
@ IBeamCursor
@ ImhMultiLine
@ transparent
Definition qnamespace.h:47
@ Key_Select
@ Key_Space
Definition qnamespace.h:513
@ Key_Up
Definition qnamespace.h:678
@ Key_Down
Definition qnamespace.h:680
@ Key_Back
Definition qnamespace.h:846
@ Key_Home
Definition qnamespace.h:675
@ Key_End
Definition qnamespace.h:676
@ Key_No
@ ShiftModifier
@ ControlModifier
@ NoModifier
@ NoBrush
@ MouseFocusReason
Definition brush.cpp:5
DBusConnection * connection
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLboolean r
[2]
GLbitfield GLuint64 timeout
[4]
GLfloat GLfloat f
GLsizei range
GLsizei GLsizei GLfloat distance
GLint GLsizei width
GLenum type
GLbitfield flags
GLenum GLuint GLintptr offset
const GLchar * marker
GLuint name
GLint GLsizei GLsizei GLenum format
GLint y
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLdouble s
[6]
Definition qopenglext.h:235
GLenum query
const GLubyte * c
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
static QT_BEGIN_NAMESPACE bool shouldEnableInputMethod(QPlainTextEdit *control)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
static QT_BEGIN_NAMESPACE bool shouldEnableInputMethod(QTextEdit *textedit)
Definition qtextedit.cpp:44
#define emit
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
QVideoFrameFormat::PixelFormat fmt
const char property[13]
Definition qwizard.cpp:101
QList< int > list
[14]
QObject::connect nullptr
QVBoxLayout * layout
view viewport() -> scroll(dx, dy, deviceRect)
edit isVisible()
app setAttribute(Qt::AA_DontShowIconsInMenus)
QDBusArgument argument