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
droparea.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#include <QApplication>
4#include <QClipboard>
5#include <QMimeData>
6#include <QWidget>
7
8namespace droparea {
9struct DropArea : public QWidget {
10 void paste();
14};
15
18{
19 const QClipboard *clipboard = QApplication::clipboard();
20 const QMimeData *mimeData = clipboard->mimeData();
21
22 if (mimeData->hasImage()) {
23 setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
24 } else if (mimeData->hasHtml()) {
27 } else if (mimeData->hasText()) {
30 } else {
31 setText(tr("Cannot display data"));
32 }
33}
35
36} // droparea
The QClipboard class provides access to the window system clipboard.
Definition qclipboard.h:20
const QMimeData * mimeData(Mode mode=Clipboard) const
Returns a pointer to a QMimeData representation of the current clipboard data (can be \nullptr if the...
static QClipboard * clipboard()
Returns the object for interacting with the clipboard.
\inmodule QtCore
Definition qmimedata.h:16
QVariant imageData() const
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null varia...
bool hasHtml() const
Returns true if the object can return HTML (MIME type text/html); otherwise returns false.
bool hasImage() const
Returns true if the object can return an image; otherwise returns false.
bool hasText() const
Returns true if the object can return plain text (MIME type text/plain); otherwise returns false.
QString html() const
Returns a string if the data stored in the object is HTML (MIME type text/html); otherwise returns an...
QString text() const
Returns a plain text (MIME type text/plain) representation of the data.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
TextFormat
@ RichText
@ PlainText
#define tr(X)
QMimeData * mimeData
void setText(QString)
void setTextFormat(Qt::TextFormat)
void setPixmap(QPixmap)