Drag Drop Images from WebPage into QTextEdit
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!!
Re: Drag Drop Images from WebPage into QTextEdit
[wiki]QTextBrowser with images and CSS[/wiki]
Re: Drag Drop Images from WebPage into QTextEdit
subclass QTextEdit insertFromMimedata or so ...
here a sample ....
http://www.qt-apps.org/content/show....?content=80234
Code:
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() ) {
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") ) {
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;
}
}
Re: Drag Drop Images from WebPage into QTextEdit
Quote:
Originally Posted by
wysota
[wiki]QTextBrowser with images and CSS[/wiki]
Did you mean [WIKI]Drop files and images on QTextEdit[/WIKI]? :)
Re: Drag Drop Images from WebPage into QTextEdit
Eeem.... yeah, I think I did :)
Re: Drag Drop Images from WebPage into QTextEdit
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) :)
Re: Drag Drop Images from WebPage into QTextEdit
See thread "QTextEdit and delayed image loading".
Re: Drag Drop Images from WebPage into QTextEdit
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