PDA

View Full Version : Drag Drop Images from WebPage into QTextEdit



Nemo
20th May 2008, 11:43
Hi guys,

Does QTextEdit have support for images copied from Web ? I mean when a user cut/copies/pastes data from the Web, I end up with place holders in my richtextbox editor which I have derived from QTextEdit. I tried overwriting canInsertfromMimeData and insertFromMimeData, the code segment for source->hasImage() does not execute. I even used the source->hasHtml() this seems to work fine but yet no Images. Any help will be appreciated. Thanks in advance!!

wysota
20th May 2008, 14:34
QTextBrowser with images and CSS

patrik08
20th May 2008, 16:23
subclass QTextEdit insertFromMimedata or so ...

here a sample ....

http://www.qt-apps.org/content/show.php/GraphicsViewEdit+Layer?content=80234




void TextWriter::insertFromMime( const QMimeData * source )
{

if ( source->formats().contains("application/x-picslists") ) {
/* multiple image list */
QByteArray dd = source->data("application/x-picslists");
QList<SPics> li = OpenImageGroup(QString(dd));
for (int i=0; i<li.size(); i++) {
SPics conni = li[i];
RegisterImage(conni,true);
}
return;
}
if ( source->hasImage() ) {
QDateTime timer1( QDateTime::currentDateTime() );
const QString TimestampsMs = QString("%1-%2-image").arg(timer1.toTime_t()).arg(timer1.toString("zzz"));
QPixmap aspixmape = qvariant_cast<QPixmap>(source->imageData());
if (!aspixmape.isNull()) {
insertPixmap(aspixmape);
}
return;
}
/* external html */

if ( source->formats().contains("text/html") ) {
QString draghtml = source->html();
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(draghtml);
textCursor().insertFragment(fragment);
return;
}
/* external plain text incomming */
if ( source->hasText() ) {
textCursor().insertText(source->text());
return;
}
if ( source->hasUrls() ) {
QList<QUrl> urls = source->urls();
for ( int i = 0; i < urls.size(); ++i ) {
QUrl gettyurl(urls.at(i));
//////////// qDebug() << "### gettyurl " << gettyurl.toString();
if (gettyurl.scheme() == "file") {
ImageonCursor(gettyurl.toLocalFile());
} else if (gettyurl.scheme() == "http") {
Gloader *grephttp = new Gloader();
grephttp->Setting(this,i,gettyurl);
grephttp->start(QThread::LowPriority);

/* grep class Gloader on
http://fop-miniscribus.googlecode.com/svn/trunk/GraphicsViewEdit/include/mimedataeditor.h
*/

}

}

return;
}


}

jpn
20th May 2008, 21:43
QTextBrowser with images and CSS
Did you mean Drop files and images on QTextEdit? :)

wysota
21st May 2008, 08:34
Eeem.... yeah, I think I did :)

Nemo
21st May 2008, 09:13
Yeah!! I had checked that out before, no go! See I will explain what is happening. When I dragging just text there is not issue, Just dragging images no text it okay. Only when I just Ctrl + A or Just select Text and Pics together thats when I hit the problem. Now I have an idea what to do ...if I can get just get the <img> tags and then download the images to a temp location and then changes the src of the <img> to these images I will be okay. But the issue how do I get the <img> tags, you like an html editor without having to parse ( find replace ? ) the html. ( yeah, yeah ...I am lazy) :)

jpn
21st May 2008, 10:20
See thread "QTextEdit and delayed image loading".

viswanathan
15th December 2009, 09:35
Hello All,
I am new to Qt. In my project, I am also coming up with same issue. I will want to copy contents (contents include text, images combined) from a web page or any external source and paste in my qtextedit. But, images are not getting displayed and only the text gets pasted. If I copy images alone and try to paste, it is displayed in qtextedit :confused:. If I am correct, the issue is related to collecting mimedata. When I copy image alone, mimedata format is stored as Image. But it doesn't work when trying to copy text and image together. I wish that someone will help me to resolve this issue.

Thanks
Viswanathan