[Interest] QTextDocument | QPdfWriter | Internal Links

Igor Mironchik igor.mironchik at gmail.com
Sun Feb 21 21:22:29 CET 2016


Again the answer to my own question:

seems that currently QTextDocument supports external links only.

Even if set HTML with <a name="title"></a> and <a href="#title"></a> 
doesn't work...

It's good suggestion to Qt's guys to implement internals links in 
QTextDocument.

On 20.02.2016 10:01, Igor Mironchik wrote:
> Hi,
>
> I'm trying to understand how to work with internal links in PDF.
>
> Here is the simple code:
>
> #include <QTextDocument>
> #include <QPdfWriter>
> #include <QApplication>
> #include <QTextCharFormat>
> #include <QTextCursor>
>
>
> int main( int argc, char ** argv )
> {
>     QApplication app( argc, argv );
>
>     QPdfWriter pdf( "/home/igor/test.pdf" );
>
>     QTextDocument doc;
>
>     QTextCharFormat fmt;
>     fmt.setAnchorName( "title" );
>     fmt.setAnchor( true );
>
>     QTextCursor c( &doc );
>     c.insertText( 
> "Title\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
> "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", fmt );
>
>     QTextCharFormat link;
>     link.setAnchorHref( "title" );
>     link.setAnchor( true );
>
>     c.insertText( "Go to title", link );
>
>     doc.print( &pdf );
>
>     return 0;
> }
>
> But when I click on "Go to title" in PDF, viewer tries to open file 
> "title" instead of navigating through the PDF.
>
> How to correctly set anchors and links in QTextDocument?




More information about the Interest mailing list