aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/doc_src_dnd.qdoc
blob: 40df804a6b741aac27b4e2a28edea523988f95b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! [0]
void MyQt3Widget::customStartDragFunction()
{
    QDragObject *d = new QTextDrag( myHighlightedText(), this );
    d->dragCopy();
    // do NOT delete d.
}
//! [0]


//! [1]
void MyQt3Widget::dragEnterEvent(QDragEnterEvent* event)
{
    event->accept(
        QTextDrag::canDecode(event) ||
        QImageDrag::canDecode(event)
    );
}
//! [1]


//! [2]
void MyQt3Widget::dropEvent(QDropEvent* event)
{
    QImage image;
    QString text;

    if ( QImageDrag::decode(event, image) ) {
        insertImageAt(image, event->pos());
    } else if ( QTextDrag::decode(event, text) ) {
        insertTextAt(text, event->pos());
    }
}
//! [2]