Results 1 to 2 of 2

Thread: How to disply Simplified Chinese in QTextBrowser

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question How to disply Simplified Chinese in QTextBrowser

    When I tried to disply some html code (coded using "text/css ,Gb2312") in a textbrowser !
    It just shows garbled code like this。

    Hrer is the code

    QTexrBrowser ts=new QTextBrowser();
    QString html,css;
    ts->setOpenExternalLinks(true);
    QTextCodec::setCodecForTr(QTextCodec::codecForName ("GB2312"));
    /*
    * creat html code*/

    html=
    "<html><head>"
    "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>"
    "<title>XJTU PORTAL</title><type='text/css' href='format.css'>"//important
    "</head><body>"
    "<img src='xjtu_logo.gif' width='199' height='45' align='absmiddle'><br>"
    "<div align='center' class='style1'> <p>西安交大门户系统常用链接</p></div>"
    "<p><span class='style2'><a href='http://www.xjtu.edu.cn'>交大主页</a></span></p>"
    "<p class='style2'><a href='http://stu.xjtu.edu.cn'>学生邮箱</a></p>"
    "<p class='style2'><a href='http://bbs.xjtu.edu.cn'>兵马俑BBS </a></p>"
    "</body></html>" ;
    /*creat css code used in html*/
    css = ".style1 {color: #FF0000}"
    ".style2 {color: #00FF00}";
    // Crate a QTextDocument with the defined HTML, CSS and the images
    QTextDocument *doc = new QTextDocument;
    /*
    * This shows how to bind the images, where the name for QUrl is the same name
    * which you use in your HTML and CSS. In QPixmap just use the normal syntax of
    * the Qt resource system.
    */
    doc->addResource( QTextDocument::ImageResource, QUrl( "xjtu_logo.gif" ), QPixmap( "iconsets/system/default/portal/xjtu_logo.gif" ) );

    /*
    * And now bind the css, which you have defined in the QString css.
    */
    doc->addResource( QTextDocument::StyleSheetResource, QUrl( "format.css" ), css );
    doc->setHtml( html ); // binds the HTML to the QTextDocument
    ts->setDocument(doc);

    /************************************/

    The red code is write in Simplified chinese !
    Last edited by xjtu; 21st April 2008 at 08:36. Reason: provide the source code

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
  •  
Qt is a trademark of The Qt Company.