Results 1 to 5 of 5

Thread: HTML in QTextView

  1. #1
    Join Date
    Jul 2007
    Posts
    7
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default HTML in QTextView

    Hi,

    I am sending a file to the QTextView with piece of HTML code (Table).
    Sometimes the results are shown in HTML i.e. as in a web browser
    and sometime the actual code "file" is shown.
    Then if the code is resubmitted it is shown properly (by the user).
    I don't want to make the user submit twice the results.
    How can i force the QTextView to accept the code in HTML
    and how can I make it accept the file as a plain text?

    I have tried to send the tags <html> and </html>
    and it does not have the effect on the code.

    thank for any help,
    genick

  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: HTML in QTextView

    Could you prepare a minimal compilable example reproducing the problem?

  3. #3
    Join Date
    Jul 2007
    Posts
    7
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: HTML in QTextView

    Thanks for the help

    The call for the dialog is make by this

    Qt Code:
    1. class ShowResults;
    2.  
    3. if (!showResults){
    4. showResults = new ShowResults (this, "showResutls");
    5. connect(this, SIGNAL(newData(QString)),
    6. showResults, SLOT(newData(QString)));
    7. }
    8. showResults->show();
    9. showResults->raise();
    10. showResults->setActiveWindow();
    11. filename = workingFileName ;
    12. emit newData(workingFileName);
    To copy to clipboard, switch view to plain text mode 

    This the header file

    Qt Code:
    1. #ifndef FINDDIALOG_H
    2. #define FINDDIALOG_H
    3. #include <qdialog.h>
    4. class QCheckBox;
    5. class QLabel;
    6. class QLineEdit;
    7. class QTextView;
    8. class QProcess;
    9.  
    10. class ShowResults : public QDialog {
    11. Q_OBJECT
    12. public:
    13. ShowResults(QWidget *parent = 0, const char *name = 0 );
    14. QString fileName;
    15. signals:
    16.  
    17. public slots:
    18. void readFromStdout();
    19. void scrollToTop();
    20. void clearOutput();
    21. void newData(QString fileName);
    22.  
    23. private slots:
    24. void init();
    25.  
    26. private:
    27. QPushButton *closeButton;
    28. QPushButton *clearButton;
    29. QTextView *output;
    30. QProcess *proc;
    31. int curPosX;
    32. };
    33.  
    34. #endif
    To copy to clipboard, switch view to plain text mode 

    This the implementation

    Qt Code:
    1. #include <qcheckbox.h>
    2. #include <qlabel.h>
    3. #include <qlayout.h>
    4. #include <qlineedit.h>
    5. #include <qpushbutton.h>
    6. #include <qtextview.h>
    7. #include <qprocess.h>
    8. #include <qstring.h>
    9. #include <qfile.h>
    10. #include <qdir.h>
    11. #include <qmessagebox.h>
    12.  
    13. #include "showResults.h"
    14.  
    15. ShowResults::ShowResults(QWidget *parent, const char *name)
    16. // ,QString FileName )
    17. : QDialog(parent, name)
    18. {
    19. setGeometry( QRect( 400, 40, 660, 640 ) );
    20. setCaption(tr("Gas Dynamics Calculator: The Results"));
    21. output = new QTextView( this );
    22. output->setGeometry( QRect( 15, 10, 630, 550 ) );
    23.  
    24. closeButton = new QPushButton(tr("Close Window"), this);
    25. closeButton->setGeometry( QRect( 200, 580, 100, 40 ) );
    26. connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
    27. clearButton = new QPushButton(tr("Clear Window"), this);
    28. clearButton->setGeometry( QRect( 340, 580, 100, 40 ) );
    29. connect(clearButton, SIGNAL(clicked()), this, SLOT(clearOutput()));
    30. init();
    31. }
    32.  
    33. void ShowResults::init()
    34. {
    35. proc = 0;
    36. output->setText("<html> </html>");
    37. }
    38.  
    39. void ShowResults::readFromStdout()
    40. {
    41. curPosX = output->contentsHeight() - 30 ;
    42. output->append( proc->readStdout() );
    43. }
    44.  
    45. void ShowResults::clearOutput()
    46. {
    47. output->setText("");
    48. }
    49.  
    50. void ShowResults::scrollToTop()
    51. {
    52. curPosX = output->contentsHeight()- 30;
    53. output->setContentsPos( curPosX, 0 );
    54. }
    55.  
    56. void ShowResults::newData(QString FileName)
    57. {
    58. if (!proc){
    59. proc = new QProcess( this );
    60. connect( proc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()) );
    61. connect( proc, SIGNAL(processExited()), this, SLOT(scrollToTop()) );
    62. // the gd/gd program sent the html file below
    63. proc->setArguments( "./gd/gd" );
    64. proc->addArgument( FileName );
    65. }
    66. curPosX = output->contentsHeight();
    67. output->setContentsPos( curPosX, 0 );
    68. QString notice, notice1, caption;
    69. output->setContentsPos( curPosX, 0 );
    70. if ( !proc->start() ) {
    71. QMessageBox::critical( 0,
    72. tr("Fatal error"),
    73. tr("Could not start the gd program."),
    74. tr("Quit") );
    75. exit( -1 );
    76. }
    77. }
    To copy to clipboard, switch view to plain text mode 



    This is the HTML code send to

    html Code:
    1. <tr class="text"><td align="center">
    2. <table border=1 width="100%" >
    3. <thead>
    4. <tr>
    5. <th align=left bgcolor="#fffeaa" colspan=2 >Normal Shock </th>
    6. <th align=left bgcolor="#00ff5a" colspan=2 >Input: Mx </th>
    7. <th align=left bgcolor="#9ae0ee" colspan=1 >k = 1.4 </th>
    8. </tr>
    9. <tr>
    10. <th align=center >Mx </th>
    11. <th align=center >My </th>
    12. <th align=center >Ty/Tx </th>
    13. <th align=center >&rho;y/&rho;x </th>
    14. <th align=center >Py/Px </th>
    15. <th align=center >P0y/P0x </th>
    16. </tr>
    17. </thead>
    18. <tbody>
    19. <tr>
    20. <td align=right > 1.5 </td>
    21. <td align=right > 0.701089 </td>
    22. <td align=right > 1.32022 </td>
    23. <td align=right > 1.86207 </td>
    24. <td align=right > 2.45833 </td>
    25. <td align=right > 0.929787 </td>
    26. </tr>
    27. </tbody>
    28. </table>
    29. </td>
    30. </tr>
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 19th September 2007 at 15:54. Reason: missing [code] tags

  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: HTML in QTextView

    Have you tried calling setFormat(Qt::RichText) on the text view? BTW. You should be using QTextBrowser or QTextEdit instead of QTextView...

  5. #5
    Join Date
    Jul 2007
    Posts
    7
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: HTML in QTextView

    I have changed to QTextBrowser and it seems to solve the problem.

    Thanks

    genick
    www.potto.org

Similar Threads

  1. Loading images in html in a QTextBrowser
    By BasicPoke in forum Newbie
    Replies: 1
    Last Post: 6th June 2007, 21:51
  2. Parsing HTML
    By stevey in forum Qt Programming
    Replies: 2
    Last Post: 1st December 2006, 20:01
  3. Replies: 1
    Last Post: 18th July 2006, 12:06
  4. Replies: 1
    Last Post: 17th March 2006, 08:01
  5. [Qt 4.1]using html in QTextEdit from designer
    By patcito in forum Qt Programming
    Replies: 5
    Last Post: 16th January 2006, 22: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.