Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
textedit.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtGui>
5#include <QTextEdit>
6
7class TextEdit : public QTextEdit
8{
10public:
11 TextEdit(QWidget *parent = nullptr);
12
13 bool canInsertFromMimeData(const QMimeData *source) const override;
14 void insertFromMimeData(const QMimeData *source) override;
15};
16
17TextEdit::TextEdit(QWidget *parent)
18 : QTextEdit(parent)
19{
20}
21
22//! [0]
23bool TextEdit::canInsertFromMimeData( const QMimeData *source ) const
24{
25 if (source->hasImage())
26 return true;
27 else
28 return QTextEdit::canInsertFromMimeData(source);
29}
30//! [0]
31
32//! [1]
33void TextEdit::insertFromMimeData( const QMimeData *source )
34{
35 if (source->hasImage())
36 {
37 QImage image = qvariant_cast<QImage>(source->imageData());
38 QTextCursor cursor = this->textCursor();
39 QTextDocument *document = this->document();
40 document->addResource(QTextDocument::ImageResource, QUrl("image"), image);
41 cursor.insertImage("image");
42 }
43}
44//! [1]
void insertFromMimeData(const QMimeData *source) override
[0]
Definition textedit.cpp:33
bool canInsertFromMimeData(const QMimeData *source) const override
[0]
Definition textedit.cpp:23