Qt 6.x
The Qt SDK
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
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 textFormat(Qt::AutoText)
93{
95 preferRichText = false;
97 inDrag = false;
98}
99
101{
103 cursor.beginEditBlock();
104
105 QTextBlockFormat blockFmt = cursor.blockFormat();
106
107 QTextListFormat listFmt;
109 listFmt.setIndent(blockFmt.indent() + 1);
110
111 blockFmt.setIndent(0);
112 cursor.setBlockFormat(blockFmt);
113
114 cursor.createList(listFmt);
115
116 cursor.endEditBlock();
118}
119
121{
122 Q_Q(QTextEdit);
124 control->setPalette(q->palette());
125
126 QObject::connect(control, SIGNAL(microFocusChanged()), q, SLOT(updateMicroFocus()));
127 QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)), q, SLOT(_q_adjustScrollbars()));
130 QObject::connect(control, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
132
134 QObject::connect(control, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool)));
135 QObject::connect(control, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool)));
136 QObject::connect(control, SIGNAL(copyAvailable(bool)), q, SIGNAL(copyAvailable(bool)));
137 QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged()));
138 QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(_q_cursorPositionChanged()));
139#if QT_CONFIG(cursor)
141#endif
142
143 QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus()));
144
146 // set a null page size initially to avoid any relayouting until the textedit
147 // is shown. relayoutDocument() will take care of setting the page size to the
148 // viewport dimensions later.
149 doc->setPageSize(QSize(0, 0));
151 doc->setDefaultFont(q->font());
152 doc->setUndoRedoEnabled(false); // flush undo buffer.
153 doc->setUndoRedoEnabled(true);
154
155 if (!html.isEmpty())
156 control->setHtml(html);
157
158 hbar->setSingleStep(20);
159 vbar->setSingleStep(20);
160
161 viewport->setBackgroundRole(QPalette::Base);
162 q->setMouseTracking(true);
163 q->setAcceptDrops(true);
164 q->setFocusPolicy(Qt::StrongFocus);
165 q->setAttribute(Qt::WA_KeyCompression);
166 q->setAttribute(Qt::WA_InputMethodEnabled);
167 q->setInputMethodHints(Qt::ImhMultiLine);
168#ifndef QT_NO_CURSOR
169 viewport->setCursor(Qt::IBeamCursor);
170#endif
171}
172
174{
175 if (!contentsRect.isValid()) {
176 viewport->update();
177 return;
178 }
179 const int xOffset = horizontalOffset();
180 const int yOffset = verticalOffset();
181 const QRectF visibleRect(xOffset, yOffset, viewport->width(), viewport->height());
182
183 QRect r = contentsRect.intersected(visibleRect).toAlignedRect();
184 if (r.isEmpty())
185 return;
186
187 r.translate(-xOffset, -yOffset);
188 viewport->update(r);
189}
190
192{
193 Q_Q(QTextEdit);
194 emit q->cursorPositionChanged();
195#if QT_CONFIG(accessibility)
196 QAccessibleTextCursorEvent event(q, q->textCursor().position());
197 QAccessible::updateAccessibility(&event);
198#endif
199}
200
201#if QT_CONFIG(cursor)
203{
204 Q_Q(QTextEdit);
206 if (block.isValid() && !q->isReadOnly()) {
209 if (viewport->cursor().shape() != Qt::PointingHandCursor)
210 cursorToRestoreAfterHover = viewport->cursor().shape();
212 }
213 }
214 viewport->setCursor(cursor);
215}
216#endif
217
219{
221 bool moved = false;
222 qreal lastY = control->cursorRect(cursor).top();
223 qreal distance = 0;
224 // move using movePosition to keep the cursor's x
225 do {
227 distance += qAbs(y - lastY);
228 lastY = y;
229 moved = cursor.movePosition(op, moveMode);
230 } while (moved && distance < viewport->height());
231
232 if (moved) {
233 if (op == QTextCursor::Up) {
234 cursor.movePosition(QTextCursor::Down, moveMode);
235 vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
236 } else {
237 cursor.movePosition(QTextCursor::Up, moveMode);
238 vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
239 }
240 }
242}
243
244#if QT_CONFIG(scrollbar)
245static QSize documentSize(QWidgetTextControl *control)
246{
247 QTextDocument *doc = control->document();
249
250 QSize docSize;
251
252 if (QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout)) {
253 docSize = tlayout->dynamicDocumentSize().toSize();
254 int percentageDone = tlayout->layoutStatus();
255 // extrapolate height
256 if (percentageDone > 0)
257 docSize.setHeight(docSize.height() * 100 / percentageDone);
258 } else {
259 docSize = layout->documentSize().toSize();
260 }
261
262 return docSize;
263}
264
266{
268 return;
269 ignoreAutomaticScrollbarAdjustment = true; // avoid recursion, #106108
270
271 QSize viewportSize = viewport->size();
272 QSize docSize = documentSize(control);
273
274 // due to the recursion guard we have to repeat this step a few times,
275 // as adding/removing a scroll bar will cause the document or viewport
276 // size to change
277 // ideally we should loop until the viewport size and doc size stabilize,
278 // but in corner cases they might fluctuate, so we need to limit the
279 // number of iterations
280 for (int i = 0; i < 4; ++i) {
281 hbar->setRange(0, docSize.width() - viewportSize.width());
282 hbar->setPageStep(viewportSize.width());
283
284 vbar->setRange(0, docSize.height() - viewportSize.height());
285 vbar->setPageStep(viewportSize.height());
286
287 // if we are in left-to-right mode widening the document due to
288 // lazy layouting does not require a repaint. If in right-to-left
289 // the scroll bar has the value zero and it visually has the maximum
290 // value (it is visually at the right), then widening the document
291 // keeps it at value zero but visually adjusts it to the new maximum
292 // on the right, hence we need an update.
293 if (q_func()->isRightToLeft())
294 viewport->update();
295
296 _q_showOrHideScrollBars();
297
298 const QSize oldViewportSize = viewportSize;
299 const QSize oldDocSize = docSize;
300
301 // make sure the document is layouted if the viewport width changes
302 viewportSize = viewport->size();
303 if (viewportSize.width() != oldViewportSize.width())
305
306 docSize = documentSize(control);
307 if (viewportSize == oldViewportSize && docSize == oldDocSize)
308 break;
309 }
311}
312#endif
313
314// rect is in content coordinates
316{
317 const QRect rect = _rect.toRect();
318 if ((vbar->isVisible() && vbar->maximum() < rect.bottom())
319 || (hbar->isVisible() && hbar->maximum() < rect.right()))
321 const int visibleWidth = viewport->width();
322 const int visibleHeight = viewport->height();
323 const bool rtl = q_func()->isRightToLeft();
324
325 if (rect.x() < horizontalOffset()) {
326 if (rtl)
327 hbar->setValue(hbar->maximum() - rect.x());
328 else
329 hbar->setValue(rect.x());
330 } else if (rect.x() + rect.width() > horizontalOffset() + visibleWidth) {
331 if (rtl)
332 hbar->setValue(hbar->maximum() - (rect.x() + rect.width() - visibleWidth));
333 else
334 hbar->setValue(rect.x() + rect.width() - visibleWidth);
335 }
336
337 if (rect.y() < verticalOffset())
338 vbar->setValue(rect.y());
339 else if (rect.y() + rect.height() > verticalOffset() + visibleHeight)
340 vbar->setValue(rect.y() + rect.height() - visibleHeight);
341}
342
602 : QAbstractScrollArea(*new QTextEditPrivate, parent)
603{
604 Q_D(QTextEdit);
605 d->init();
606}
607
612 : QAbstractScrollArea(dd, parent)
613{
614 Q_D(QTextEdit);
615 d->init();
616}
617
623 : QAbstractScrollArea(*new QTextEditPrivate, parent)
624{
625 Q_D(QTextEdit);
626 d->init(text);
627}
628
629
630
635{
636}
637
644{
645 Q_D(const QTextEdit);
646 return d->control->textCursor().charFormat().fontPointSize();
647}
648
655{
656 Q_D(const QTextEdit);
657 return d->control->textCursor().charFormat().fontFamilies().toStringList().value(0, QString());
658}
659
666{
667 Q_D(const QTextEdit);
668 return d->control->textCursor().charFormat().fontWeight();
669}
670
678{
679 Q_D(const QTextEdit);
680 return d->control->textCursor().charFormat().fontUnderline();
681}
682
690{
691 Q_D(const QTextEdit);
692 return d->control->textCursor().charFormat().fontItalic();
693}
694
701{
702 Q_D(const QTextEdit);
703 return d->control->textCursor().charFormat().foreground().color();
704}
705
714{
715 Q_D(const QTextEdit);
716 const QBrush &brush = d->control->textCursor().charFormat().background();
717 return brush.style() == Qt::NoBrush ? Qt::transparent : brush.color();
718}
719
726{
727 Q_D(const QTextEdit);
728 return d->control->textCursor().charFormat().font();
729}
730
737void QTextEdit::setAlignment(Qt::Alignment a)
738{
739 Q_D(QTextEdit);
741 fmt.setAlignment(a);
742 QTextCursor cursor = d->control->textCursor();
743 cursor.mergeBlockFormat(fmt);
744 d->control->setTextCursor(cursor);
745 d->relayoutDocument();
746}
747
753Qt::Alignment QTextEdit::alignment() const
754{
755 Q_D(const QTextEdit);
756 return d->control->textCursor().blockFormat().alignment();
757}
758
769{
770 Q_D(QTextEdit);
771 d->control->setDocument(document);
772 d->updateDefaultTextOption();
773 d->relayoutDocument();
774}
775
777{
778 Q_D(const QTextEdit);
779 return d->control->document();
780}
781
796{
797 Q_D(const QTextEdit);
798 return d->placeholderText;
799}
800
801void QTextEdit::setPlaceholderText(const QString &placeholderText)
802{
803 Q_D(QTextEdit);
804 if (d->placeholderText != placeholderText) {
805 d->placeholderText = placeholderText;
806 if (d->control->document()->isEmpty())
807 d->viewport->update();
808 }
809}
810
815{
817}
818
826{
827 Q_D(QTextEdit);
828 d->control->setTextCursor(cursor);
829}
830
837{
838 Q_D(const QTextEdit);
839 return d->control->textCursor();
840}
841
847void QTextEdit::setFontFamily(const QString &fontFamily)
848{
850 fmt.setFontFamilies({fontFamily});
852}
853
863{
865 fmt.setFontPointSize(s);
867}
868
879{
881 fmt.setFontWeight(w);
883}
884
891void QTextEdit::setFontUnderline(bool underline)
892{
894 fmt.setFontUnderline(underline);
896}
897
905{
907 fmt.setFontItalic(italic);
909}
910
917{
919 fmt.setForeground(QBrush(c));
921}
922
931{
933 fmt.setBackground(QBrush(c));
935}
936
943{
945 fmt.setFont(f);
947}
948
960{
961 Q_D(QTextEdit);
962 d->control->undo();
963}
964
966{
967 Q_D(QTextEdit);
968 d->control->redo();
969}
970
983#ifndef QT_NO_CLIPBOARD
994{
995 Q_D(QTextEdit);
996 d->control->cut();
997}
998
1006{
1007 Q_D(QTextEdit);
1008 d->control->copy();
1009}
1010
1026{
1027 Q_D(QTextEdit);
1028 d->control->paste();
1029}
1030#endif
1031
1045{
1046 Q_D(QTextEdit);
1047 // clears and sets empty content
1048 d->control->clear();
1049}
1050
1051
1058{
1059 Q_D(QTextEdit);
1060 d->control->selectAll();
1061}
1062
1066{
1067 Q_D(QTextEdit);
1068#ifndef QT_NO_CONTEXTMENU
1069 if (e->type() == QEvent::ContextMenu
1070 && static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) {
1071 Q_D(QTextEdit);
1073 const QPoint cursorPos = cursorRect().center();
1074 QContextMenuEvent ce(QContextMenuEvent::Keyboard, cursorPos, d->viewport->mapToGlobal(cursorPos));
1075 ce.setAccepted(e->isAccepted());
1076 const bool result = QAbstractScrollArea::event(&ce);
1077 e->setAccepted(ce.isAccepted());
1078 return result;
1079 } else if (e->type() == QEvent::ShortcutOverride
1080 || e->type() == QEvent::ToolTip) {
1081 d->sendControlEvent(e);
1082 }
1083#else
1084 Q_UNUSED(d);
1085#endif // QT_NO_CONTEXTMENU
1086#ifdef QT_KEYPAD_NAVIGATION
1087 if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) {
1088 if (QApplicationPrivate::keypadNavigationEnabled())
1089 d->sendControlEvent(e);
1090 }
1091#endif
1092 return QAbstractScrollArea::event(e);
1093}
1094
1099{
1100 Q_D(QTextEdit);
1101 if (e->timerId() == d->autoScrollTimer.timerId()) {
1102 QRect visible = d->viewport->rect();
1103 QPoint pos;
1104 if (d->inDrag) {
1105 pos = d->autoScrollDragPos;
1106 visible.adjust(qMin(visible.width()/3,20), qMin(visible.height()/3,20),
1107 -qMin(visible.width()/3,20), -qMin(visible.height()/3,20));
1108 } else {
1109 const QPoint globalPos = QCursor::pos();
1110 pos = d->viewport->mapFromGlobal(globalPos);
1111 QMouseEvent ev(QEvent::MouseMove, pos, mapTo(topLevelWidget(), pos), globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
1112 mouseMoveEvent(&ev);
1113 }
1114 int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height();
1115 int deltaX = qMax(pos.x() - visible.left(), visible.right() - pos.x()) - visible.width();
1116 int delta = qMax(deltaX, deltaY);
1117 if (delta >= 0) {
1118 if (delta < 7)
1119 delta = 7;
1120 int timeout = 4900 / (delta * delta);
1121 d->autoScrollTimer.start(timeout, this);
1122
1123 if (deltaY > 0)
1124 d->vbar->triggerAction(pos.y() < visible.center().y() ?
1127 if (deltaX > 0)
1128 d->hbar->triggerAction(pos.x() < visible.center().x() ?
1131 }
1132 }
1133#ifdef QT_KEYPAD_NAVIGATION
1134 else if (e->timerId() == d->deleteAllTimer.timerId()) {
1135 d->deleteAllTimer.stop();
1136 clear();
1137 }
1138#endif
1139}
1140
1157{
1158 Q_D(QTextEdit);
1159 d->control->setPlainText(text);
1160 d->preferRichText = false;
1161}
1162
1171{
1172 Q_D(const QTextEdit);
1173 return d->control->toPlainText();
1174}
1175
1198#ifndef QT_NO_TEXTHTMLPARSER
1200{
1201 Q_D(QTextEdit);
1202 d->control->setHtml(text);
1203 d->preferRichText = true;
1204}
1205
1207{
1208 Q_D(const QTextEdit);
1209 return d->control->toHtml();
1210}
1211#endif
1212
1213#if QT_CONFIG(textmarkdownreader) && QT_CONFIG(textmarkdownwriter)
1247#endif
1248
1249#if QT_CONFIG(textmarkdownreader)
1250void QTextEdit::setMarkdown(const QString &markdown)
1251{
1252 Q_D(const QTextEdit);
1253 d->control->setMarkdown(markdown);
1254}
1255#endif
1256
1257#if QT_CONFIG(textmarkdownwriter)
1258QString QTextEdit::toMarkdown(QTextDocument::MarkdownFeatures features) const
1259{
1260 Q_D(const QTextEdit);
1261 return d->control->toMarkdown(features);
1262}
1263#endif
1264
1268{
1269 Q_D(QTextEdit);
1270
1271#ifdef QT_KEYPAD_NAVIGATION
1272 switch (e->key()) {
1273 case Qt::Key_Select:
1274 if (QApplicationPrivate::keypadNavigationEnabled()) {
1275 // code assumes linksaccessible + editable isn't meaningful
1276 if (d->control->textInteractionFlags() & Qt::TextEditable) {
1277 setEditFocus(!hasEditFocus());
1278 } else {
1279 if (!hasEditFocus())
1280 setEditFocus(true);
1281 else {
1282 QTextCursor cursor = d->control->textCursor();
1283 QTextCharFormat charFmt = cursor.charFormat();
1284 if (!(d->control->textInteractionFlags() & Qt::LinksAccessibleByKeyboard)
1285 || !cursor.hasSelection() || charFmt.anchorHref().isEmpty()) {
1286 e->accept();
1287 return;
1288 }
1289 }
1290 }
1291 }
1292 break;
1293 case Qt::Key_Back:
1294 case Qt::Key_No:
1295 if (!QApplicationPrivate::keypadNavigationEnabled()
1296 || (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())) {
1297 e->ignore();
1298 return;
1299 }
1300 break;
1301 default:
1302 if (QApplicationPrivate::keypadNavigationEnabled()) {
1303 if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) {
1304 if (e->text()[0].isPrint())
1305 setEditFocus(true);
1306 else {
1307 e->ignore();
1308 return;
1309 }
1310 }
1311 }
1312 break;
1313 }
1314#endif
1315#ifndef QT_NO_SHORTCUT
1316
1317 Qt::TextInteractionFlags tif = d->control->textInteractionFlags();
1318
1321 e->accept();
1323 return;
1324 } else if (e ==QKeySequence::SelectNextPage) {
1325 e->accept();
1327 return;
1328 }
1329 }
1332 e->accept();
1334 return;
1335 } else if (e == QKeySequence::MoveToNextPage) {
1336 e->accept();
1338 return;
1339 }
1340 }
1341
1342 if (!(tif & Qt::TextEditable)) {
1343 switch (e->key()) {
1344 case Qt::Key_Space:
1345 e->accept();
1346 if (e->modifiers() & Qt::ShiftModifier)
1347 d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
1348 else
1349 d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
1350 break;
1351 default:
1352 d->sendControlEvent(e);
1353 if (!e->isAccepted() && e->modifiers() == Qt::NoModifier) {
1354 if (e->key() == Qt::Key_Home) {
1355 d->vbar->triggerAction(QAbstractSlider::SliderToMinimum);
1356 e->accept();
1357 } else if (e->key() == Qt::Key_End) {
1358 d->vbar->triggerAction(QAbstractSlider::SliderToMaximum);
1359 e->accept();
1360 }
1361 }
1362 if (!e->isAccepted()) {
1363 QAbstractScrollArea::keyPressEvent(e);
1364 }
1365 }
1366 return;
1367 }
1368#endif // QT_NO_SHORTCUT
1369
1370 {
1371 QTextCursor cursor = d->control->textCursor();
1372 const QString text = e->text();
1373 if (cursor.atBlockStart()
1374 && (d->autoFormatting & AutoBulletList)
1375 && (text.size() == 1)
1376 && (text.at(0) == u'-' || text.at(0) == u'*')
1377 && (!cursor.currentList())) {
1378
1379 d->createAutoBulletList();
1380 e->accept();
1381 return;
1382 }
1383 }
1384
1385 d->sendControlEvent(e);
1386#ifdef QT_KEYPAD_NAVIGATION
1387 if (!e->isAccepted()) {
1388 switch (e->key()) {
1389 case Qt::Key_Up:
1390 case Qt::Key_Down:
1391 if (QApplicationPrivate::keypadNavigationEnabled()) {
1392 // Cursor position didn't change, so we want to leave
1393 // these keys to change focus.
1394 e->ignore();
1395 return;
1396 }
1397 break;
1398 case Qt::Key_Back:
1399 if (!e->isAutoRepeat()) {
1400 if (QApplicationPrivate::keypadNavigationEnabled()) {
1401 if (document()->isEmpty() || !(d->control->textInteractionFlags() & Qt::TextEditable)) {
1402 setEditFocus(false);
1403 e->accept();
1404 } else if (!d->deleteAllTimer.isActive()) {
1405 e->accept();
1406 d->deleteAllTimer.start(750, this);
1407 }
1408 } else {
1409 e->ignore();
1410 return;
1411 }
1412 }
1413 break;
1414 default: break;
1415 }
1416 }
1417#endif
1418}
1419
1423{
1424 Q_D(QTextEdit);
1425 if (!isReadOnly())
1426 d->handleSoftwareInputPanel();
1427#ifdef QT_KEYPAD_NAVIGATION
1428 if (QApplicationPrivate::keypadNavigationEnabled()) {
1429 if (!e->isAutoRepeat() && e->key() == Qt::Key_Back
1430 && d->deleteAllTimer.isActive()) {
1431 d->deleteAllTimer.stop();
1432 QTextCursor cursor = d->control->textCursor();
1433 QTextBlockFormat blockFmt = cursor.blockFormat();
1434
1435 QTextList *list = cursor.currentList();
1436 if (list && cursor.atBlockStart()) {
1437 list->remove(cursor.block());
1438 } else if (cursor.atBlockStart() && blockFmt.indent() > 0) {
1439 blockFmt.setIndent(blockFmt.indent() - 1);
1440 cursor.setBlockFormat(blockFmt);
1441 } else {
1442 cursor.deletePreviousChar();
1443 }
1445 e->accept();
1446 return;
1447 }
1448 }
1449#endif
1450 e->ignore();
1451}
1452
1461{
1462 Q_UNUSED(type);
1463 Q_UNUSED(name);
1464 return QVariant();
1465}
1466
1470{
1471 Q_D(QTextEdit);
1472
1473 if (d->lineWrap == NoWrap) {
1474 QTextDocument *doc = d->control->document();
1475 QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");
1476
1477 if (!doc->pageSize().isNull()
1478 && alignmentProperty.userType() == QMetaType::Bool
1479 && !alignmentProperty.toBool()) {
1480
1481 d->_q_adjustScrollbars();
1482 return;
1483 }
1484 }
1485
1486 if (d->lineWrap != FixedPixelWidth
1487 && e->oldSize().width() != e->size().width())
1488 d->relayoutDocument();
1489 else
1490 d->_q_adjustScrollbars();
1491}
1492
1494{
1495 QTextDocument *doc = control->document();
1497
1498 if (QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout)) {
1500 tlayout->setFixedColumnWidth(lineWrapColumnOrWidth);
1501 else
1502 tlayout->setFixedColumnWidth(-1);
1503 }
1504
1505 QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout);
1506 QSize lastUsedSize;
1507 if (tlayout)
1508 lastUsedSize = tlayout->dynamicDocumentSize().toSize();
1509 else
1510 lastUsedSize = layout->documentSize().toSize();
1511
1512 // ignore calls to _q_adjustScrollbars caused by an emission of the
1513 // usedSizeChanged() signal in the layout, as we're calling it
1514 // later on our own anyway (or deliberately not) .
1515 const bool oldIgnoreScrollbarAdjustment = ignoreAutomaticScrollbarAdjustment;
1517
1518 int width = viewport->width();
1521 else if (lineWrap == QTextEdit::NoWrap) {
1522 QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");
1523 if (alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) {
1524
1525 width = 0;
1526 }
1527 }
1528
1529 doc->setPageSize(QSize(width, -1));
1530 if (tlayout)
1531 tlayout->ensureLayouted(verticalOffset() + viewport->height());
1532
1533 ignoreAutomaticScrollbarAdjustment = oldIgnoreScrollbarAdjustment;
1534
1535 QSize usedSize;
1536 if (tlayout)
1537 usedSize = tlayout->dynamicDocumentSize().toSize();
1538 else
1539 usedSize = layout->documentSize().toSize();
1540
1541 // this is an obscure situation in the layout that can happen:
1542 // if a character at the end of a line is the tallest one and therefore
1543 // influencing the total height of the line and the line right below it
1544 // is always taller though, then it can happen that if due to line breaking
1545 // that tall character wraps into the lower line the document not only shrinks
1546 // horizontally (causing the character to wrap in the first place) but also
1547 // vertically, because the original line is now smaller and the one below kept
1548 // its size. So a layout with less width _can_ take up less vertical space, too.
1549 // If the wider case causes a vertical scroll bar to appear and the narrower one
1550 // (narrower because the vertical scroll bar takes up horizontal space)) to disappear
1551 // again then we have an endless loop, as _q_adjustScrollBars sets new ranges on the
1552 // scroll bars, the QAbstractScrollArea will find out about it and try to show/hide
1553 // the scroll bars again. That's why we try to detect this case here and break out.
1554 //
1555 // (if you change this please also check the layoutingLoop() testcase in
1556 // QTextEdit's autotests)
1557 if (lastUsedSize.isValid()
1558 && !vbar->isHidden()
1559 && viewport->width() < lastUsedSize.width()
1560 && usedSize.height() < lastUsedSize.height()
1561 && usedSize.height() <= viewport->height())
1562 return;
1563
1565}
1566
1568{
1569 const int xOffset = horizontalOffset();
1570 const int yOffset = verticalOffset();
1571
1572 QRect r = e->rect();
1573 p->translate(-xOffset, -yOffset);
1574 r.translate(xOffset, yOffset);
1575
1576 QTextDocument *doc = control->document();
1577 QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(doc->documentLayout());
1578
1579 // the layout might need to expand the root frame to
1580 // the viewport if NoWrap is set
1581 if (layout)
1582 layout->setViewport(viewport->rect());
1583
1584 control->drawContents(p, r, q_func());
1585
1586 if (layout)
1587 layout->setViewport(QRect());
1588
1589 if (!placeholderText.isEmpty() && doc->isEmpty() && !control->isPreediting()) {
1590 const QColor col = control->palette().placeholderText().color();
1591 p->setPen(col);
1592 const int margin = int(doc->documentMargin());
1593 p->drawText(viewport->rect().adjusted(margin, margin, -margin, -margin), Qt::AlignTop | Qt::TextWordWrap, placeholderText);
1594 }
1595}
1596
1608{
1609 Q_D(QTextEdit);
1610 QPainter p(d->viewport);
1611 d->paint(&p, e);
1612}
1613
1615{
1616 Q_Q(QTextEdit);
1617 emit q->currentCharFormatChanged(fmt);
1618}
1619
1621{
1622 QTextDocument *doc = control->document();
1623
1625 QTextOption::WrapMode oldWrapMode = opt.wrapMode();
1626
1628 opt.setWrapMode(QTextOption::NoWrap);
1629 else
1630 opt.setWrapMode(wordWrap);
1631
1632 if (opt.wrapMode() != oldWrapMode)
1634}
1635
1639{
1640 Q_D(QTextEdit);
1641#ifdef QT_KEYPAD_NAVIGATION
1642 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())
1643 setEditFocus(true);
1644#endif
1645 d->sendControlEvent(e);
1646}
1647
1651{
1652 Q_D(QTextEdit);
1653 d->inDrag = false; // paranoia
1654 const QPoint pos = e->position().toPoint();
1655 d->sendControlEvent(e);
1656 if (!(e->buttons() & Qt::LeftButton))
1657 return;
1658 if (e->source() == Qt::MouseEventNotSynthesized) {
1659 const QRect visible = d->viewport->rect();
1660 if (visible.contains(pos))
1661 d->autoScrollTimer.stop();
1662 else if (!d->autoScrollTimer.isActive())
1663 d->autoScrollTimer.start(100, this);
1664 }
1665}
1666
1670{
1671 Q_D(QTextEdit);
1672 d->sendControlEvent(e);
1673 if (e->source() == Qt::MouseEventNotSynthesized && d->autoScrollTimer.isActive()) {
1674 d->autoScrollTimer.stop();
1676 }
1677 if (!isReadOnly() && rect().contains(e->position().toPoint()))
1678 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
1679 d->clickCausedFocus = 0;
1680}
1681
1685{
1686 Q_D(QTextEdit);
1687 d->sendControlEvent(e);
1688}
1689
1693{
1694 Q_D(const QTextEdit);
1695 if (!d->tabChangesFocus && d->control->textInteractionFlags() & Qt::TextEditable)
1696 return false;
1697 return QAbstractScrollArea::focusNextPrevChild(next);
1698}
1699
1700#ifndef QT_NO_CONTEXTMENU
1717{
1718 Q_D(QTextEdit);
1719 d->sendControlEvent(e);
1720}
1721#endif // QT_NO_CONTEXTMENU
1722
1723#if QT_CONFIG(draganddrop)
1726void QTextEdit::dragEnterEvent(QDragEnterEvent *e)
1727{
1728 Q_D(QTextEdit);
1729 d->inDrag = true;
1730 d->sendControlEvent(e);
1731}
1732
1735void QTextEdit::dragLeaveEvent(QDragLeaveEvent *e)
1736{
1737 Q_D(QTextEdit);
1738 d->inDrag = false;
1739 d->autoScrollTimer.stop();
1740 d->sendControlEvent(e);
1741}
1742
1745void QTextEdit::dragMoveEvent(QDragMoveEvent *e)
1746{
1747 Q_D(QTextEdit);
1748 d->autoScrollDragPos = e->position().toPoint();
1749 if (!d->autoScrollTimer.isActive())
1750 d->autoScrollTimer.start(100, this);
1751 d->sendControlEvent(e);
1752}
1753
1756void QTextEdit::dropEvent(QDropEvent *e)
1757{
1758 Q_D(QTextEdit);
1759 d->inDrag = false;
1760 d->autoScrollTimer.stop();
1761 d->sendControlEvent(e);
1762}
1763
1764#endif // QT_CONFIG(draganddrop)
1765
1769{
1770 Q_D(QTextEdit);
1771#ifdef QT_KEYPAD_NAVIGATION
1772 if (d->control->textInteractionFlags() & Qt::TextEditable
1773 && QApplicationPrivate::keypadNavigationEnabled()
1774 && !hasEditFocus())
1775 setEditFocus(true);
1776#endif
1777 d->sendControlEvent(e);
1778 const bool emptyEvent = e->preeditString().isEmpty() && e->commitString().isEmpty()
1779 && e->attributes().isEmpty();
1780 if (emptyEvent)
1781 return;
1783}
1784
1788{
1789 Q_D(QTextEdit);
1790 if (isRightToLeft())
1791 dx = -dx;
1792 d->viewport->scroll(dx, dy);
1794}
1795
1799{
1801}
1802
1806{
1807 Q_D(const QTextEdit);
1808 switch (query) {
1809 case Qt::ImEnabled:
1810 return isEnabled();
1811 case Qt::ImHints:
1814 case Qt::ImReadOnly:
1815 return isReadOnly();
1816 default:
1817 break;
1818 }
1819
1820 const QPointF offset(-d->horizontalOffset(), -d->verticalOffset());
1821 switch (argument.userType()) {
1822 case QMetaType::QRectF:
1823 argument = argument.toRectF().translated(-offset);
1824 break;
1825 case QMetaType::QPointF:
1826 argument = argument.toPointF() - offset;
1827 break;
1828 case QMetaType::QRect:
1829 argument = argument.toRect().translated(-offset.toPoint());
1830 break;
1831 case QMetaType::QPoint:
1832 argument = argument.toPoint() - offset;
1833 break;
1834 default:
1835 break;
1836 }
1837
1838 const QVariant v = d->control->inputMethodQuery(query, argument);
1839 switch (v.userType()) {
1840 case QMetaType::QRectF:
1841 return v.toRectF().translated(offset);
1842 case QMetaType::QPointF:
1843 return v.toPointF() + offset;
1844 case QMetaType::QRect:
1845 return v.toRect().translated(offset.toPoint());
1846 case QMetaType::QPoint:
1847 return v.toPoint() + offset.toPoint();
1848 default:
1849 break;
1850 }
1851 return v;
1852}
1853
1857{
1858 Q_D(QTextEdit);
1859 if (e->reason() == Qt::MouseFocusReason) {
1860 d->clickCausedFocus = 1;
1861 }
1862 QAbstractScrollArea::focusInEvent(e);
1863 d->sendControlEvent(e);
1864}
1865
1869{
1870 Q_D(QTextEdit);
1871 QAbstractScrollArea::focusOutEvent(e);
1872 d->sendControlEvent(e);
1873}
1874
1878{
1879 Q_D(QTextEdit);
1880 if (!d->anchorToScrollToWhenVisible.isEmpty()) {
1881 scrollToAnchor(d->anchorToScrollToWhenVisible);
1882 d->anchorToScrollToWhenVisible.clear();
1883 d->showCursorOnInitialShow = false;
1884 } else if (d->showCursorOnInitialShow) {
1885 d->showCursorOnInitialShow = false;
1887 }
1888}
1889
1893{
1894 Q_D(QTextEdit);
1895 QAbstractScrollArea::changeEvent(e);
1896 if (e->type() == QEvent::ApplicationFontChange
1897 || e->type() == QEvent::FontChange) {
1898 d->control->document()->setDefaultFont(font());
1899 } else if (e->type() == QEvent::ActivationChange) {
1900 d->control->setPalette(palette());
1901 if (!isActiveWindow())
1902 d->autoScrollTimer.stop();
1903 } else if (e->type() == QEvent::EnabledChange) {
1904 e->setAccepted(isEnabled());
1905 d->control->setPalette(palette());
1906 d->sendControlEvent(e);
1907 } else if (e->type() == QEvent::PaletteChange) {
1908 d->control->setPalette(palette());
1909 } else if (e->type() == QEvent::LayoutDirectionChange) {
1910 d->sendControlEvent(e);
1911 }
1912}
1913
1916#if QT_CONFIG(wheelevent)
1917void QTextEdit::wheelEvent(QWheelEvent *e)
1918{
1919 Q_D(QTextEdit);
1920 if (!(d->control->textInteractionFlags() & Qt::TextEditable)) {
1921 if (e->modifiers() & Qt::ControlModifier) {
1922 float delta = e->angleDelta().y() / 120.f;
1923 zoomInF(delta);
1924 return;
1925 }
1926 }
1927 QAbstractScrollArea::wheelEvent(e);
1928 updateMicroFocus();
1929}
1930#endif
1931
1932#ifndef QT_NO_CONTEXTMENU
1943{
1944 Q_D(QTextEdit);
1945 return d->control->createStandardContextMenu(QPointF(), this);
1946}
1947
1959{
1960 Q_D(QTextEdit);
1961 return d->control->createStandardContextMenu(position, this);
1962}
1963#endif // QT_NO_CONTEXTMENU
1964
1969{
1970 Q_D(const QTextEdit);
1971 return d->control->cursorForPosition(d->mapToContents(pos));
1972}
1973
1979{
1980 Q_D(const QTextEdit);
1981 if (cursor.isNull())
1982 return QRect();
1983
1984 QRect r = d->control->cursorRect(cursor).toRect();
1985 r.translate(-d->horizontalOffset(),-d->verticalOffset());
1986 return r;
1987}
1988
1994{
1995 Q_D(const QTextEdit);
1996 QRect r = d->control->cursorRect().toRect();
1997 r.translate(-d->horizontalOffset(),-d->verticalOffset());
1998 return r;
1999}
2000
2001
2007{
2008 Q_D(const QTextEdit);
2009 return d->control->anchorAt(d->mapToContents(pos));
2010}
2011
2028{
2029 Q_D(const QTextEdit);
2030 return d->control->overwriteMode();
2031}
2032
2034{
2035 Q_D(QTextEdit);
2036 d->control->setOverwriteMode(overwrite);
2037}
2038
2054{
2055 Q_D(const QTextEdit);
2056 return d->control->document()->defaultTextOption().tabStopDistance();
2057}
2058
2060{
2061 Q_D(QTextEdit);
2062 QTextOption opt = d->control->document()->defaultTextOption();
2063 if (opt.tabStopDistance() == distance || distance < 0)
2064 return;
2065 opt.setTabStopDistance(distance);
2066 d->control->document()->setDefaultTextOption(opt);
2067}
2068
2076{
2077 Q_D(const QTextEdit);
2078 return d->control->cursorWidth();
2079}
2080
2082{
2083 Q_D(QTextEdit);
2084 d->control->setCursorWidth(width);
2085}
2086
2099{
2100 Q_D(const QTextEdit);
2101 return d->control->acceptRichText();
2102}
2103
2105{
2106 Q_D(QTextEdit);
2107 d->control->setAcceptRichText(accept);
2108}
2109
2140{
2141 Q_D(QTextEdit);
2142 d->control->setExtraSelections(selections);
2143}
2144
2152{
2153 Q_D(const QTextEdit);
2154 return d->control->extraSelections();
2155}
2156
2168{
2169 Q_D(const QTextEdit);
2170 return d->control->QWidgetTextControl::createMimeDataFromSelection();
2171}
2172
2183{
2184 Q_D(const QTextEdit);
2185 return d->control->QWidgetTextControl::canInsertFromMimeData(source);
2186}
2187
2198{
2199 Q_D(QTextEdit);
2200 d->control->QWidgetTextControl::insertFromMimeData(source);
2201}
2202
2214{
2215 Q_D(const QTextEdit);
2216 return !(d->control->textInteractionFlags() & Qt::TextEditable);
2217}
2218
2220{
2221 Q_D(QTextEdit);
2222 Qt::TextInteractionFlags flags = Qt::NoTextInteraction;
2223 if (ro) {
2225#if QT_CONFIG(textbrowser)
2226 if (qobject_cast<QTextBrowser *>(this))
2228#endif
2229 } else {
2231 }
2232 d->control->setTextInteractionFlags(flags);
2236}
2237
2248void QTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags)
2249{
2250 Q_D(QTextEdit);
2251 d->control->setTextInteractionFlags(flags);
2252}
2253
2254Qt::TextInteractionFlags QTextEdit::textInteractionFlags() const
2255{
2256 Q_D(const QTextEdit);
2257 return d->control->textInteractionFlags();
2258}
2259
2269{
2270 Q_D(QTextEdit);
2271 d->control->mergeCurrentCharFormat(modifier);
2272}
2273
2281{
2282 Q_D(QTextEdit);
2283 d->control->setCurrentCharFormat(format);
2284}
2285
2290{
2291 Q_D(const QTextEdit);
2292 return d->control->currentCharFormat();
2293}
2294
2307QTextEdit::AutoFormatting QTextEdit::autoFormatting() const
2308{
2309 Q_D(const QTextEdit);
2310 return d->autoFormatting;
2311}
2312
2313void QTextEdit::setAutoFormatting(AutoFormatting features)
2314{
2315 Q_D(QTextEdit);
2316 d->autoFormatting = features;
2317}
2318
2328{
2329 Q_D(QTextEdit);
2330 d->control->insertPlainText(text);
2331}
2332
2346#ifndef QT_NO_TEXTHTMLPARSER
2348{
2349 Q_D(QTextEdit);
2350 d->control->insertHtml(text);
2351}
2352#endif // QT_NO_TEXTHTMLPARSER
2353
2360{
2361 Q_D(QTextEdit);
2362 if (name.isEmpty())
2363 return;
2364
2365 if (!isVisible()) {
2366 d->anchorToScrollToWhenVisible = name;
2367 return;
2368 }
2369
2370 QPointF p = d->control->anchorPosition(name);
2371 const int newPosition = qRound(p.y());
2372 if ( d->vbar->maximum() < newPosition )
2373 d->_q_adjustScrollbars();
2374 d->vbar->setValue(newPosition);
2375}
2376
2385{
2386 zoomInF(range);
2387}
2388
2397{
2398 zoomInF(-range);
2399}
2400
2405{
2406 if (range == 0.f)
2407 return;
2408 QFont f = font();
2409 const float newSize = f.pointSizeF() + range;
2410 if (newSize <= 0)
2411 return;
2412 f.setPointSizeF(newSize);
2413 setFont(f);
2414}
2415
2427{
2428 Q_D(QTextEdit);
2429 d->control->moveCursor(operation, mode);
2430}
2431
2437{
2438 Q_D(const QTextEdit);
2439 return d->control->canPaste();
2440}
2441
2450#ifndef QT_NO_PRINTER
2452{
2453 Q_D(const QTextEdit);
2454 d->control->print(printer);
2455}
2456#endif
2457
2468{
2469 Q_D(const QTextEdit);
2470 return d->tabChangesFocus;
2471}
2472
2474{
2475 Q_D(QTextEdit);
2476 d->tabChangesFocus = b;
2477}
2478
2502{
2503 Q_D(const QTextEdit);
2504 return d->lineWrap;
2505}
2506
2508{
2509 Q_D(QTextEdit);
2510 if (d->lineWrap == wrap)
2511 return;
2512 d->lineWrap = wrap;
2513 d->updateDefaultTextOption();
2514 d->relayoutDocument();
2515}
2516
2533{
2534 Q_D(const QTextEdit);
2535 return d->lineWrapColumnOrWidth;
2536}
2537
2539{
2540 Q_D(QTextEdit);
2541 d->lineWrapColumnOrWidth = w;
2542 d->relayoutDocument();
2543}
2544
2555{
2556 Q_D(const QTextEdit);
2557 return d->wordWrap;
2558}
2559
2561{
2562 Q_D(QTextEdit);
2563 if (mode == d->wordWrap)
2564 return;
2565 d->wordWrap = mode;
2566 d->updateDefaultTextOption();
2567}
2568
2574bool QTextEdit::find(const QString &exp, QTextDocument::FindFlags options)
2575{
2576 Q_D(QTextEdit);
2577 return d->control->find(exp, options);
2578}
2579
2593#if QT_CONFIG(regularexpression)
2594bool QTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options)
2595{
2596 Q_D(QTextEdit);
2597 return d->control->find(exp, options);
2598}
2599#endif
2600
2654{
2655 Q_D(QTextEdit);
2656 Qt::TextFormat format = d->textFormat;
2657 if (d->textFormat == Qt::AutoText)
2659#ifndef QT_NO_TEXTHTMLPARSER
2660 if (format == Qt::RichText)
2661 setHtml(text);
2662 else
2663#else
2665#endif
2667}
2668
2669
2680{
2681 Q_D(QTextEdit);
2682 const bool atBottom = isReadOnly() ? d->verticalOffset() >= d->vbar->maximum() :
2683 d->control->textCursor().atEnd();
2684 d->control->append(text);
2685 if (atBottom)
2686 d->vbar->setValue(d->vbar->maximum());
2687}
2688
2694{
2695 Q_D(QTextEdit);
2696 d->control->ensureCursorVisible();
2697}
2698
2721
2722#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:593
Reason reason() const
Returns the reason for this context event.
Definition qevent.h:613
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:302
@ 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
@ PaletteChange
Definition qcoreevent.h:94
@ ApplicationFontChange
Definition qcoreevent.h:91
@ ContextMenu
Definition qcoreevent.h:119
bool isAccepted() const
Definition qcoreevent.h:303
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
\reentrant
Definition qfont.h:20
static QInputMethod * inputMethod()
returns the input method.
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:624
void update(Qt::InputMethodQueries queries)
Called by the input item to inform the platform input methods when there has been state changes in ed...
The QKeyEvent class describes a key event.
Definition qevent.h:423
Definition qlist.h:74
void remove(qsizetype i, qsizetype n=1)
Definition qlist.h:787
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtGui
Definition qevent.h:195
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
QVariant property(const char *name) const
Returns the value of the object's name property.
Definition qobject.cpp:4187
\inmodule QtGui
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
const QBrush & placeholderText() const
Definition qpalette.h:101
\inmodule QtCore\reentrant
Definition qpoint.h:214
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
\inmodule QtCore\reentrant
Definition qrect.h:483
QRect toAlignedRect() const noexcept
Definition qrect.cpp:2330
constexpr QRect toRect() const noexcept
Returns a QRect based on the values of this rectangle.
Definition qrect.h:845
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:497
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:652
QRectF intersected(const QRectF &other) const noexcept
Definition qrect.h:833
\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:372
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:181
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:175
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:851
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:172
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:244
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:232
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:178
\inmodule QtCore \reentrant
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:577
\inmodule QtCore
Definition qsize.h:207
bool isNull() const noexcept
Returns true if both the width and height are 0.0 (ignoring the sign); otherwise returns false.
Definition qsize.h:312
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
Definition qsize.h:390
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:138
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:126
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1079
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
MarkerType marker() const
void setIndent(int indent)
Sets the paragraph's indentation.
int indent() const
Returns the paragraph's indent.
\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.
QString anchorHref() const
Returns the text format's hypertext link, or an empty string if none has been set.
\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:79
QTextEdit::LineWrapMode lineWrap
Definition qtextedit_p.h:87
void _q_cursorPositionChanged()
void _q_adjustScrollbars()
void pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode)
Qt::CursorShape cursorToRestoreAfterHover
void _q_repaintContents(const QRectF &contentsRect)
int horizontalOffset() const
Definition qtextedit_p.h:61
uint ignoreAutomaticScrollbarAdjustment
Definition qtextedit_p.h:91
void _q_hoveredBlockWithMarkerChanged(const QTextBlock &block)
int verticalOffset() const
Definition qtextedit_p.h:63
void _q_ensureVisible(const QRectF &rect)
void createAutoBulletList()
void _q_currentCharFormatChanged(const QTextCharFormat &format)
QString placeholderText
uint showCursorOnInitialShow
Definition qtextedit_p.h:93
void paint(QPainter *p, QPaintEvent *e)
void init(const QString &html=QString())
void updateDefaultTextOption()
QTextOption::WrapMode wordWrap
Definition qtextedit_p.h:89
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 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().
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)
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)
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
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 setStyle(Style style)
Sets the list format's style.
void setIndent(int indent)
Sets the list format's indentation.
\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:359
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:64
int userType() const
Definition qvariant.h:336
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
QTextCursor textCursor() const
void setHtml(const QString &text)
virtual QMimeData * createMimeDataFromSelection() const
void setTextCursor(const QTextCursor &cursor, bool selectionClipboard=false)
virtual Q_INVOKABLE QVariant loadResource(int type, const QUrl &name)
QRectF cursorRect(const QTextCursor &cursor) const
void drawContents(QPainter *painter, const QRectF &rect=QRectF(), QWidget *widget=nullptr)
virtual void insertFromMimeData(const QMimeData *source)
virtual bool canInsertFromMimeData(const QMimeData *source) const
void setPalette(const QPalette &pal)
QTextDocument * document() const
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:9959
QString text
QCursor cursor
void textChanged(const QString &newText)
double e
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:152
@ LeftButton
Definition qnamespace.h:57
@ TextSelectableByMouse
@ TextEditable
@ TextBrowserInteraction
@ TextEditorInteraction
@ LinksAccessibleByKeyboard
@ TextSelectableByKeyboard
@ NoTextInteraction
@ WA_KeyCompression
Definition qnamespace.h:299
@ WA_InputMethodEnabled
Definition qnamespace.h:294
TextFormat
@ RichText
@ PlainText
@ AutoText
@ StrongFocus
Definition qnamespace.h:109
@ TextWordWrap
Definition qnamespace.h:173
@ MouseEventNotSynthesized
CursorShape
@ PointingHandCursor
@ IBeamCursor
@ ImhMultiLine
@ transparent
Definition qnamespace.h:46
@ Key_Select
@ Key_Space
Definition qnamespace.h:512
@ Key_Up
Definition qnamespace.h:673
@ Key_Down
Definition qnamespace.h:675
@ Key_Back
Definition qnamespace.h:841
@ Key_Home
Definition qnamespace.h:670
@ Key_End
Definition qnamespace.h:671
@ Key_No
@ ShiftModifier
@ ControlModifier
@ NoModifier
@ NoBrush
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
@ MouseFocusReason
Definition brush.cpp:5
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:281
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
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
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
GLenum query
const GLubyte * c
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
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:92
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
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent