Results 1 to 8 of 8

Thread: Drag Drop Images from WebPage into QTextEdit

  1. #1
    Join Date
    Jan 2006
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default 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!!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag Drop Images from WebPage into QTextEdit

    [wiki]QTextBrowser with images and CSS[/wiki]

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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


    Qt Code:
    1. void TextWriter::insertFromMime( const QMimeData * source )
    2. {
    3.  
    4. if ( source->formats().contains("application/x-picslists") ) {
    5. /* multiple image list */
    6. QByteArray dd = source->data("application/x-picslists");
    7. QList<SPics> li = OpenImageGroup(QString(dd));
    8. for (int i=0; i<li.size(); i++) {
    9. SPics conni = li[i];
    10. RegisterImage(conni,true);
    11. }
    12. return;
    13. }
    14. if ( source->hasImage() ) {
    15. QDateTime timer1( QDateTime::currentDateTime() );
    16. const QString TimestampsMs = QString("%1-%2-image").arg(timer1.toTime_t()).arg(timer1.toString("zzz"));
    17. QPixmap aspixmape = qvariant_cast<QPixmap>(source->imageData());
    18. if (!aspixmape.isNull()) {
    19. insertPixmap(aspixmape);
    20. }
    21. return;
    22. }
    23. /* external html */
    24.  
    25. if ( source->formats().contains("text/html") ) {
    26. QString draghtml = source->html();
    27. QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(draghtml);
    28. textCursor().insertFragment(fragment);
    29. return;
    30. }
    31. /* external plain text incomming */
    32. if ( source->hasText() ) {
    33. textCursor().insertText(source->text());
    34. return;
    35. }
    36. if ( source->hasUrls() ) {
    37. QList<QUrl> urls = source->urls();
    38. for ( int i = 0; i < urls.size(); ++i ) {
    39. QUrl gettyurl(urls.at(i));
    40. //////////// qDebug() << "### gettyurl " << gettyurl.toString();
    41. if (gettyurl.scheme() == "file") {
    42. ImageonCursor(gettyurl.toLocalFile());
    43. } else if (gettyurl.scheme() == "http") {
    44. Gloader *grephttp = new Gloader();
    45. grephttp->Setting(this,i,gettyurl);
    46. grephttp->start(QThread::LowPriority);
    47.  
    48. /* grep class Gloader on
    49.   http://fop-miniscribus.googlecode.com/svn/trunk/GraphicsViewEdit/include/mimedataeditor.h
    50.   */
    51.  
    52. }
    53.  
    54. }
    55.  
    56. return;
    57. }
    58.  
    59.  
    60. }
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to patrik08 for this useful post:

    fnmblot (20th May 2008)

  5. #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: Drag Drop Images from WebPage into QTextEdit

    Quote Originally Posted by wysota View Post
    [wiki]QTextBrowser with images and CSS[/wiki]
    Did you mean [WIKI]Drop files and images on QTextEdit[/WIKI]?
    J-P Nurmi

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag Drop Images from WebPage into QTextEdit

    Eeem.... yeah, I think I did

  7. #6
    Join Date
    Jan 2006
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default 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)

  8. #7
    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: Drag Drop Images from WebPage into QTextEdit

    See thread "QTextEdit and delayed image loading".
    J-P Nurmi

  9. #8
    Join Date
    Dec 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Post 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 . 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

Similar Threads

  1. Drag and Drop QTableWidget and QTableView
    By scorpion11 in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 09:33
  2. QTextEdit drag and drop
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2008, 16:41
  3. Problem with a cursor during Drag and Drop
    By mtrpoland in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2007, 15:46
  4. Replies: 7
    Last Post: 8th September 2006, 16:19
  5. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41

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.