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
clipwindow.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 <QtWidgets>
5#include <QMimeData>
6
7#include "clipwindow.h"
8
10 : QMainWindow(parent)
11{
12 clipboard = QApplication::clipboard();
13
14 QWidget *centralWidget = new QWidget(this);
15 QWidget *currentItem = new QWidget(centralWidget);
16 QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), currentItem);
17 mimeTypeCombo = new QComboBox(currentItem);
18 QLabel *dataLabel = new QLabel(tr("Data:"), currentItem);
19 dataInfoLabel = new QLabel("", currentItem);
20
21 previousItems = new QListWidget(centralWidget);
22
27
28 QVBoxLayout *currentLayout = new QVBoxLayout(currentItem);
29 currentLayout->addWidget(mimeTypeLabel);
30 currentLayout->addWidget(mimeTypeCombo);
31 currentLayout->addWidget(dataLabel);
32 currentLayout->addWidget(dataInfoLabel);
33 currentLayout->addStretch(1);
34
35 QHBoxLayout *mainLayout = new QHBoxLayout(centralWidget);
36 mainLayout->addWidget(currentItem, 1);
37 mainLayout->addWidget(previousItems);
38
40 setWindowTitle(tr("Clipboard"));
41}
42
45{
46 mimeTypeCombo->clear();
47
48 QStringList formats = clipboard->mimeData()->formats();
49 if (formats.isEmpty())
50 return;
51
52 for (const auto &format : formats) {
53 QByteArray data = clipboard->mimeData()->data(format);
54 // ...
55 }
57
58 mimeTypeCombo->addItems(formats);
59
60 int size = clipboard->mimeData()->data(formats[0]).size();
61 QListWidgetItem *newItem = new QListWidgetItem(previousItems);
62 newItem->setText(tr("%1 (%2 bytes)").arg(formats[0]).arg(size));
63
65}
66
68{
69 QByteArray data = clipboard->mimeData()->data(format);
70 dataInfoLabel->setText(tr("%1 bytes").arg(data.size()));
71}
void updateData(const QString &format)
ClipWindow(QWidget *parent=nullptr)
Definition clipwindow.cpp:9
void updateClipboard()
[1]
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:494
const QMimeData * mimeData(Mode mode=Clipboard) const
Returns a pointer to a QMimeData representation of the current clipboard data (can be \nullptr if the...
void dataChanged()
This signal is emitted when the clipboard data is changed.
The QComboBox widget combines a button with a dropdown list.
Definition qcombobox.h:24
void addItems(const QStringList &texts)
Adds each of the strings in the given texts to the combobox.
Definition qcombobox.h:135
void clear()
Clears the combobox, removing all items.
static QClipboard * clipboard()
Returns the object for interacting with the clipboard.
The QHBoxLayout class lines up widgets horizontally.
Definition qboxlayout.h:78
The QLabel widget provides a text or image display.
Definition qlabel.h:20
void setText(const QString &)
Definition qlabel.cpp:263
The QListWidgetItem class provides an item for use with the QListWidget item view class.
Definition qlistwidget.h:23
The QListWidget class provides an item-based list widget.
The QMainWindow class provides a main application window.
Definition qmainwindow.h:25
QWidget * centralWidget() const
Returns the central widget for the main window.
void setCentralWidget(QWidget *widget)
Sets the given widget to be the main window's central widget.
QByteArray data(const QString &mimetype) const
Returns the data stored in the object in the format described by the MIME type specified by mimeType.
virtual QStringList formats() const
Returns a list of formats supported by the object.
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
friend class QWidget
Definition qobject.h:382
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
EGLint EGLint * formats
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
SSL_CTX int void * arg
#define tr(X)