[Qt-interest] Displaying RTF content

Brad Hards bradh at frogmouth.net
Thu Jun 9 11:45:47 CEST 2011


On Thursday 09 June 2011 15:55:21 Darryl Hunter wrote:
> Basically I have data in RTF format, that I need to display.  Is there any
> easy widget for doing this?  Or does anybody have experience with a simple
> converter that they have been able to embed in their application to do
> this? For me, it's a 1 way problem (I don't need to convert back to RTF
> afterwards - it's a static display).
I have a parser / renderer, but it isn't complete. Part of the problem is that
the QTextDocument class needs functionality (proposed but rejected) like
line spacing.

My API looks like:
void RtfDemo::openFile()
{
  QString fileName = QFileDialog::getOpenFileName( this, "Open RTF file",
                                                   QString(), "*.rtf" );

  if ( fileName.isEmpty() ) {
    return;
  }

  RtfReader::Reader *reader = new RtfReader::Reader( this );

  bool result = reader->open( fileName );

  if ( ! result ) {
    qDebug() << "failed to open file: " << fileName;
    return;
  }

  // delete m_rtfDocument;
  m_rtfDocument = new QTextDocument( this );
  RtfReader::TextDocumentRtfOutput *output = new RtfReader::TextDocumentRtfOutput( m_rtfDocument );

  reader->parseTo( output );

  QTextEdit *textEdit = new QTextEdit( this );
  setCentralWidget(textEdit);

  textEdit->setDocument( m_rtfDocument );

  m_saveTextAction->setEnabled( true );
  m_saveHtmlAction->setEnabled( true );
}

Does that look like the sort of thing you'd be interested
in helping out on?

Brad




More information about the Qt-interest-old mailing list