Results 1 to 5 of 5

Thread: QTextBrowser

  1. #1
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextBrowser

    Hi,
    I am using QT4.1.1. I cannot get the drop event in QTextBrowser.
    Here is my code
    #include <QtGui/QLabel>
    #include <QtGui/QPixmap>
    #include <QtGui/QDragEnterEvent>
    #include <QtGui/QDropEvent>
    #include <QtGui/QMouseEvent>
    #include <QtCore/QMimeData>
    #include <QtGui/QDrag>
    #include <QtGui/QPainter>
    #include <QtCore/QDebug>
    #include <QtGui/QTextBrowser>

    class QColorGroup;

    #include "dragwidget.h"


    ListView::ListView( QWidget* parent)
    :QTextBrowser (parent)
    {
    setFocusPolicy (Qt::StrongFocus);
    setAcceptDrops(true);
    }

    void ListView::mouseMoveEvent ( QMouseEvent * me)
    {
    QTextBrowser::mouseMoveEvent(me);

    if (!(me->buttons() & Qt::LeftButton))
    return;

    QByteArray itemData;
    QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    dataStream << QString("abcd");

    QMimeData *mimeData = new QMimeData;
    mimeData->setData("application/x-dnditemdata", itemData);

    QDrag *drag = new QDrag(this);
    drag->setMimeData(mimeData);
    drag->start();

    return;
    }


    void ListView::dragEnterEvent(QDragEnterEvent *event)
    {
    qDebug() << "In ListView::dragEnterEvent";
    if (event->mimeData()->hasFormat("application/x-dnditemdata")) {
    if (event->source() == this) {
    // event->setDropAction(Qt::MoveAction);
    event->accept();
    } else {
    event->acceptProposedAction();
    }
    } else {
    event->ignore();
    }
    }

    void ListView::dropEvent(QDropEvent *event)
    {
    qDebug() << "DragWidget::dropEvent" ;
    if (event->mimeData()->hasFormat("application/x-dnditemdata")) {
    QByteArray itemData = event->mimeData()->data("application/x-dnditemdata");
    QDataStream dataStream(&itemData, QIODevice::ReadOnly);

    QString str;
    dataStream >> str;

    if (event->source() == this) {
    event->accept();
    } else {
    qDebug() << "--- dropped item :: "<< str << endl;
    event->acceptProposedAction();
    }
    } else {
    event->ignore();
    }
    }


    bool ListView::viewportEvent ( QEvent * e )
    {
    QTextBrowser::viewportEvent(e);
    // if (e->type() == QEvent:rop)
    qDebug() << "type --"<< e->type () << endl;
    }


    /////////////////////////////////////////////////////////////7

    DragWidget:ragWidget(QWidget *parent)
    : QFrame(parent)
    {
    setMinimumSize(200, 200);
    setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);

    mList = new ListView(this);
    QString str = "<html><body>";
    str += "<font color=\"gray\"> 1. this is <a href=\"xxx.html\"><font color=\"gray\">abc</font></a> a gray link </font><br>";
    str += "<font color=\"gray\"> 2. this is <a href=\"xxx.html\" style= \"color:gray\">abc</a> a gray link </font><br>";
    str += "<font color=\"gray\"> 3. this is <a href=\"xxx.html\" style= \" color:gray\">abc</a> a gray link</font> <br>";
    str += "<font color=\"gray\"> 4. this is <a href=\"xxx.html\"><span style=\" text-decoration: underline; color:#808080;\">abc</span></a> a gray link </font><br>";
    str += "<font color=\"gray\"> 1. this is <a href=\"xxx.html\">abc</a> a gray link </font><br>";
    str += "</body></html>";

    mList->setHtml(str);

    }

    Please do reply me.

    Thank you

    bye,
    sree

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QTextBrowser

    Have you declare your dropEvent as protected?
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextBrowser

    Thanks for replying me

    I declared my dropEvent as protected

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTextBrowser

    Try overriding the dragMoveEvent() also.
    I got it working that way..

    Qt Code:
    1. void ListView::dragMoveEvent(QDragMoveEvent *event)
    2. {
    3. if (event->mimeData()->hasFormat("application/x-dnditemdata"))
    4. event->acceptProposedAction();
    5. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextBrowser

    Thanks a lot,
    it's working if i implement dragMoveEvent.

    I think this is a bug in QT4.1.1 as i implemented drag and drop in other widgets (eg. QListView, QWidget, etc) all of them work without implementing dragMoveEvent.

    Is it necessary that we implement dragEvent, dragMoveEvent, dragEnterEvent, and dropEvent for all the widgets for drag and drop

    regards,
    sree

Similar Threads

  1. link from QTextBrowser to QWebView
    By lamera in forum Qt Programming
    Replies: 4
    Last Post: 12th October 2008, 15:46
  2. Replies: 1
    Last Post: 5th August 2008, 20:44
  3. QTextBrowser: Cannot open
    By veda in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2007, 12:05
  4. qtextbrowser stop scrolling on append
    By tpf80 in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2007, 20:28
  5. [QT4] QtextBrowser and image size (win)
    By sebgui in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 21:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.