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
window.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 <QComboBox>
4#include <QDragEnterEvent>
5#include <QLabel>
6#include <QMimeData>
7#include <QTextBrowser>
8#include <QVBoxLayout>
9#include <QWidget>
10
11namespace dropevents {
12class Window : public QWidget
13{
14
15public:
16 explicit Window(QWidget *parent = nullptr);
17
18protected:
19 void dragEnterEvent(QDragEnterEvent *event) override;
20 void dropEvent(QDropEvent *event) override;
21
22private:
23 QComboBox *mimeTypeCombo = nullptr;
24 QTextBrowser *textBrowser = nullptr;
25 QString oldText;
26 QStringList oldMimeTypes;
27};
28
30Window::Window(QWidget *parent)
31 : QWidget(parent)
32{
34 QLabel *textLabel = new QLabel(tr("Data:"), this);
35 textBrowser = new QTextBrowser(this);
36
37 QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), this);
38 mimeTypeCombo = new QComboBox(this);
39
40 QVBoxLayout *layout = new QVBoxLayout(this);
41 layout->addWidget(textLabel);
42 layout->addWidget(textBrowser);
43 layout->addWidget(mimeTypeLabel);
44 layout->addWidget(mimeTypeCombo);
45
47 setAcceptDrops(true);
49 setWindowTitle(tr("Drop Events"));
51}
53
55void Window::dragEnterEvent(QDragEnterEvent *event)
56{
57 if (event->mimeData()->hasFormat("text/plain"))
58 event->acceptProposedAction();
59}
61
63void Window::dropEvent(QDropEvent *event)
64{
65 textBrowser->setPlainText(event->mimeData()->text());
66 mimeTypeCombo->clear();
67 mimeTypeCombo->addItems(event->mimeData()->formats());
68
69 event->acceptProposedAction();
70}
72
73} // dropevents
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.
The QLabel widget provides a text or image display.
Definition qlabel.h:20
void addWidget(QWidget *w)
Adds widget w to this layout in a manner specific to the layout.
Definition qlayout.cpp:186
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTextBrowser class provides a rich text browser with hypertext navigation.
void setPlainText(const QString &text)
Changes the text of the text edit to the string text.
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
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
void setAcceptDrops(bool on)
Definition qwidget.cpp:3436
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
void dropEvent(QDropEvent *event) override
[3]
Definition window.cpp:63
void dragEnterEvent(QDragEnterEvent *event) override
[2]
Definition window.cpp:55
struct _cl_event * event
#define tr(X)
XID Window