for example if you just set
self.textedit.setHtml("<b>Bold text</b>")
htmlCheck=self.textedit.toHtml()
hmtlCheck=
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt;
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;"><span style=" font-weight:600;">Bold text</span>
</p>
</body></html>
Why can't I just only get my setted text from the first code line back? This, what I get back, is so bad for further editing... Imagine, I write a bigger text in this. I'd like to select text and make it bold, or make a list, and detect hyperlinks in real time... I don't know how to deal with it when there is so much garbage around my code that works alone, too. And there are afaik only the .toPlainText() and .toHtml() functions... The hyperlink-thing is really simple, I could just .setText(...) and .toPlainText() and run a regex each time over all the www.'s and http's. But I also want a dynamic list functionality or bold, maybe, and thus cannot use toPlainText()...
Has someone a good advise for me?
EDIT: This one here seems to work to set selected text bold, even through different paragraphs:
def setBold(self):
cur=self.textedit.textCursor()
if cur.hasSelection():
font=self.textedit.currentFont()
font.setWeight(QFont.Bold)
self.textedit.setCurrentFont(font)
that always occur after a line break Enter? And for example, if I want to change the fontsize... I replace "font-family:'MS Shell Dlg 2'" vs. "font-family:'Arial'" and set the new html with the replaced font. Seems to work. But after I made a 2nd toHtml() it says "font-family:'MS Shell Dlg 2'" again! I don't understand this.
– user2366975 Aug 20 '13 at 18:32