#include <QGraphicsScene>
#include <QtGui>
#include <QGraphicsProxyWidget>
#include <QGraphicsTextItem>
/* qt4.4 !! */
{
Q_OBJECT
//
public:
Xedit
::Xedit( QWidget* parent
= 0 ){
setAcceptDrops(true);
}
{
qDebug() << "### dragEnterEvent ";
/////event->acceptProposedAction();
insertFromMimeData(event->mimeData());
}
void insertFromMimeData
( const QMimeData * source
) {
/* external paste drag */
qDebug() << "### insertFromMimeData ";
if ( source->formats().contains("text/html") ) {
textCursor().insertFragment(fragment);
return;
}
if ( source->hasText() ) {
textCursor().insertText(source->text());
return;
}
}
};
int main(int argc, char *argv[])
{
a.setOrganizationName("Dummy");
a.setOrganizationDomain("dummy.com");
a.setApplicationName("TestEventforward");
/////Xedit *extendededit = new Xedit;
///////extendededit->show();
view.show();
Xedit *extendededit = new Xedit;
extendededit->setReadOnly(false);
extendededit->setOpenExternalLinks(false);
grid->addWidget(extendededit, 0, 0, 1, 1);
QGraphicsProxyWidget *proxy = scene.addWidget(editor);
/* http://doc.trolltech.com/main-snapshot/qgraphicsproxywidget.html */
proxy->setAcceptDrops( true );
////proxy->setAttribute( Qt::WA_AcceptDrops , true );
text->setZValue(1.2);
extendededit->setDocument(text->document());
proxy->show();
proxy->setZValue(1.5);
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
#include "main.moc"
#include <QGraphicsScene>
#include <QtGui>
#include <QGraphicsProxyWidget>
#include <QGraphicsTextItem>
/* qt4.4 !! */
class Xedit : public QTextBrowser
{
Q_OBJECT
//
public:
Xedit::Xedit( QWidget* parent = 0 )
: QTextBrowser(parent)
{
setAcceptDrops(true);
}
void dragEnterEvent(QDragEnterEvent *event)
{
qDebug() << "### dragEnterEvent ";
/////event->acceptProposedAction();
insertFromMimeData(event->mimeData());
}
void insertFromMimeData ( const QMimeData * source )
{
/* external paste drag */
qDebug() << "### insertFromMimeData ";
if ( source->formats().contains("text/html") ) {
QString draghtml = source->html();
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(draghtml);
textCursor().insertFragment(fragment);
return;
}
if ( source->hasText() ) {
textCursor().insertText(source->text());
return;
}
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setOrganizationName("Dummy");
a.setOrganizationDomain("dummy.com");
a.setApplicationName("TestEventforward");
/////Xedit *extendededit = new Xedit;
///////extendededit->show();
QGraphicsScene scene;
QGraphicsView view(&scene);
view.show();
QWidget *editor = new QWidget;
QGridLayout *grid = new QGridLayout(editor);
Xedit *extendededit = new Xedit;
extendededit->setReadOnly(false);
extendededit->setOpenExternalLinks(false);
grid->addWidget(extendededit, 0, 0, 1, 1);
QGraphicsProxyWidget *proxy = scene.addWidget(editor);
/* http://doc.trolltech.com/main-snapshot/qgraphicsproxywidget.html */
proxy->setAcceptDrops( true );
////proxy->setAttribute( Qt::WA_AcceptDrops , true );
QGraphicsTextItem *text = scene.addText("Helo world..!");
text->setZValue(1.2);
extendededit->setDocument(text->document());
proxy->show();
proxy->setZValue(1.5);
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks