[PyQt] problems with QTextBrowser

Aaron Digulla digulla at hepe.com
Tue Apr 15 20:52:08 BST 2008


Dusan Zatkovsky schrieb:
> Hi there.
> 
> I have problem with QTextBrowser. I am writing db app, which (basically) asks 
> user for some rich text ( using dialog with QTextEdit ), then it receives 
> that text as html ( doc = self.ui.textEdit.document(),  text = 
> doc.toHtml() ). That html is converted to base64 and stored to database then.
> 
> On other place, it is readed from db, decoded from base64 and following code 
> is called:
> 
> html = utils.decB64 ( data )	# this is my own decoding method, because i
> 						# am 'hacking' base64 string ( not using =+)
> 
> self.ui.textBrowser.setHtml ( html )		# textBrowser is QTextBrowser class
> 								# constructed by .ui file
> 
> 
> Browser shows only "<" charracter.
> 
> Debugging the code, html is 'str' type and contains following string:
> 
> <html><head><meta name="qrichtext" content="1" /><style type="text/css">
> p, li { white-space: pre-wrap; }
> </style></head><body style=" font-family:'Sans Serif'; font-size:10pt; 
> font-weight:400; font-style:normal;">
> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; 
> margin-right:0px; -qt-block-indent:0; text-indent:0px;">fooo</p>
> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; 
> margin-left:0px; margin-right:0px; -qt-block-indent:0; 
> text-indent:0px;"></p></body></html>
> 
> It seems to be valid html code. I have tried to convert that string to 
> QString, but without success.
> 
> When I hardcoded that html string as one-line string directly to code ( 
> instead of calling html = utils.decB64.... ), html was shown right.
> 
> What am I doing wrong?

I have no idea; the code looks good and should do what you expect. Some
tips to debug this: Query the textBrowser for its contents right after
setHtml() with getText() and getHtml().

Also, which version of Python, Qt and PyQt are you using?

Regards,

-- 
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://darkviews.blogspot.com/          http://www.pdark.de/


More information about the PyQt mailing list