Results 1 to 5 of 5

Thread: How to use QMimeData::setHtml?

  1. #1
    Join Date
    Sep 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use QMimeData::setHtml?

    Trying to set my html text as an html mimetype into the clipboard. Text like this works:

    Qt Code:
    1. QMimeData *md = new QMimeData;
    2. md->setText(*text);
    3. QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard);
    To copy to clipboard, switch view to plain text mode 
    html like this:
    Qt Code:
    1. QMimeData *md = new QMimeData;
    2. md->setHtml(*text);
    3. QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard);
    To copy to clipboard, switch view to plain text mode 

    or this:
    Qt Code:
    1. QMimeData *md = new QMimeData;
    2. md->setData(QLatin1String("text/html"), text->toUtf8());
    3. QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard);
    To copy to clipboard, switch view to plain text mode 

    does not work. Any ideas?

  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: How to use QMimeData::setHtml?

    What does "does not work" mean in this situation? What is the content of "text"? By the way, there is no point in using pointers to QString.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QMimeData::setHtml?

    What doesn't work is that the global clipboard does not receive any new text - pasting into a field doesn't do anything either.

    Sample content of text is:

    <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'><html><head><style><!-- *{ font-family: 'Courier New', 'Monospace', 'Courier';} *{ white-space: pre-wrap; } *{color:rgb(255,255,255);} *{background-color:rgb(0,0,0);} --></style><meta http-equiv='content-type' content='text/html; charset=utf-8'></head><body><br /></span><span style="color: rgb(192,192,192); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal"> </span><span style="color: rgb(0,0,128); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal">****************************************** <br /><br /></span><span style="color: rgb(192,192,192); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal"> </span><span style="color: rgb(0,179,0); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal">Achaea, Dreams of Divine Lands<br /><br /></span><span style="color: rgb(192,192,192); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal"> </span><span style="color: rgb(0,128,128); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal">"Your fate and fame shall be<br /></span><span style="color: rgb(0,128,128); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal"> an echo and a light unto eternity."<br /><br /></span><span style="color: rgb(0,128,128); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal"> </span><span style="color: rgb(0,0,128); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal">****************************************** <br /><br /></span><span style="color: rgb(192,192,192); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal"> Achaea's IP address is 69.65.42.66<br /></span><span style="color: rgb(192,192,192); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal"> For general questions e-mail support@achaea.com.<br /></span><span style="color: rgb(192,192,192); background: rgb(0,0,0); font-weight: normal; font-style: normal; font-decoration: normal"> 212 adventurers are currently in the<br /></body></html>
    Thanks for the quick answer

  4. #4
    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: How to use QMimeData::setHtml?

    Would you try something simpler? Like:
    Qt Code:
    1. int main(int argc, char **argv){
    2. QApplication app(argc, argv);
    3. QClipboard *clip = QApplication::clipboard();
    4. QMimeData *data = new QMimeData;
    5. data->setHtml("<font color='red'>TEST</font>");
    6. clip->setMimeData(data);
    7. return app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 
    And then try pasting it somewhere where html is accepted (like QTextEdit). Don't stop the application before you paste the clipboard contents.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QMimeData::setHtml?

    Thanks. Seems it's certain text fields of Chrome do not accept it... QTextEdid did, Pidgins input field did (albeit stripped the html... while I have seen it render some before).

    So now I'm wondering what is the proper format of the HTML is it wanting...


    Added after 29 minutes:


    This worked:

    Qt Code:
    1. QMimeData *md = new QMimeData;
    2. md->setText(*text);
    3. md->setHtml(*text);
    4. QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard);
    To copy to clipboard, switch view to plain text mode 

    Thanks for the help.
    Last edited by Vadi; 25th January 2011 at 16:52.

Similar Threads

  1. Replies: 3
    Last Post: 22nd March 2010, 13:50
  2. Drag&Drop - Pointer into QMimeData?
    By droetker in forum Newbie
    Replies: 2
    Last Post: 11th October 2009, 14:14
  3. QGraphicsTextItem - setHTML()
    By Claymore in forum Qt Programming
    Replies: 7
    Last Post: 17th September 2009, 09:34
  4. Is there a known problem with QMimeData on Mac OS X?
    By Wurgl in forum Qt Programming
    Replies: 8
    Last Post: 27th February 2008, 22:21
  5. MIME database and QMimedata
    By nupul in forum Qt Programming
    Replies: 12
    Last Post: 12th April 2006, 14:36

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.