PDA

View Full Version : HTML in QTextView



genick bar-meir
18th September 2007, 21:46
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

wysota
19th September 2007, 10:37
Could you prepare a minimal compilable example reproducing the problem?

genick bar-meir
19th September 2007, 15:17
Thanks for the help

The call for the dialog is make by this


class ShowResults;

if (!showResults){
showResults = new ShowResults (this, "showResutls");
connect(this, SIGNAL(newData(QString)),
showResults, SLOT(newData(QString)));
}
showResults->show();
showResults->raise();
showResults->setActiveWindow();
filename = workingFileName ;
emit newData(workingFileName);

This the header file


#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include <qdialog.h>
class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;
class QTextView;
class QProcess;

class ShowResults : public QDialog {
Q_OBJECT
public:
ShowResults(QWidget *parent = 0, const char *name = 0 );
QString fileName;
signals:

public slots:
void readFromStdout();
void scrollToTop();
void clearOutput();
void newData(QString fileName);

private slots:
void init();

private:
QPushButton *closeButton;
QPushButton *clearButton;
QTextView *output;
QProcess *proc;
int curPosX;
};

#endif

This the implementation


#include <qcheckbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qtextview.h>
#include <qprocess.h>
#include <qstring.h>
#include <qfile.h>
#include <qdir.h>
#include <qmessagebox.h>

#include "showResults.h"

ShowResults::ShowResults(QWidget *parent, const char *name)
// ,QString FileName )
: QDialog(parent, name)
{
setGeometry( QRect( 400, 40, 660, 640 ) );
setCaption(tr("Gas Dynamics Calculator: The Results"));
output = new QTextView( this );
output->setGeometry( QRect( 15, 10, 630, 550 ) );

closeButton = new QPushButton(tr("Close Window"), this);
closeButton->setGeometry( QRect( 200, 580, 100, 40 ) );
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
clearButton = new QPushButton(tr("Clear Window"), this);
clearButton->setGeometry( QRect( 340, 580, 100, 40 ) );
connect(clearButton, SIGNAL(clicked()), this, SLOT(clearOutput()));
init();
}

void ShowResults::init()
{
proc = 0;
output->setText("<html> </html>");
}

void ShowResults::readFromStdout()
{
curPosX = output->contentsHeight() - 30 ;
output->append( proc->readStdout() );
}

void ShowResults::clearOutput()
{
output->setText("");
}

void ShowResults::scrollToTop()
{
curPosX = output->contentsHeight()- 30;
output->setContentsPos( curPosX, 0 );
}

void ShowResults::newData(QString FileName)
{
if (!proc){
proc = new QProcess( this );
connect( proc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()) );
connect( proc, SIGNAL(processExited()), this, SLOT(scrollToTop()) );
// the gd/gd program sent the html file below
proc->setArguments( "./gd/gd" );
proc->addArgument( FileName );
}
curPosX = output->contentsHeight();
output->setContentsPos( curPosX, 0 );
QString notice, notice1, caption;
output->setContentsPos( curPosX, 0 );
if ( !proc->start() ) {
QMessageBox::critical( 0,
tr("Fatal error"),
tr("Could not start the gd program."),
tr("Quit") );
exit( -1 );
}
}



This is the HTML code send to

<tr class="text"><td align="center">
<table border=1 width="100%" >
<thead>
<tr>
<th align=left bgcolor="#fffeaa" colspan=2 >Normal Shock </th>
<th align=left bgcolor="#00ff5a" colspan=2 >Input: Mx </th>
<th align=left bgcolor="#9ae0ee" colspan=1 >k = 1.4 </th>
</tr>
<tr>
<th align=center >Mx </th>
<th align=center >My </th>
<th align=center >Ty/Tx </th>
<th align=center >&rho;y/&rho;x </th>
<th align=center >Py/Px </th>
<th align=center >P0y/P0x </th>
</tr>
</thead>
<tbody>
<tr>
<td align=right > 1.5 </td>
<td align=right > 0.701089 </td>
<td align=right > 1.32022 </td>
<td align=right > 1.86207 </td>
<td align=right > 2.45833 </td>
<td align=right > 0.929787 </td>
</tr>
</tbody>
</table>
</td>
</tr>

wysota
19th September 2007, 15:59
Have you tried calling setFormat(Qt::RichText) on the text view? BTW. You should be using QTextBrowser or QTextEdit instead of QTextView...

genick bar-meir
19th September 2007, 16:59
I have changed to QTextBrowser and it seems to solve the problem.

Thanks

genick
www.potto.org