Nice rich text editor. But i tried the word processor with PyQt 5.14.2 and i saw a weird behavior. When i create a text with many different fonts (some word in Arial, some in Verdana, ecc.) and save it in a file then open the same file a can’t change the font, even if i insert a new paragraph the font is fixed on the default font.
Are you saving it with the txt extension?
If the answer is yes, txt files are plain text, that is without formatting.
Try to save it with html or htm extension.
NO, i saved in html format then reopen the file AND i can’t change font, i don’t know why… Did you tried yourself ?
Hey @Paolo_De_Stefani sorry for the delay in looking at this.
So the good news is I can reproduce what you mean. I actually noticed another issue (at least on macOS) with the current font-setting, since it tries to update the font, rather than font family it currently doesn’t work for me at all. That was fixable by changing the update to the following to apply the font family to the selection only…
self.fonts.currentFontChanged.connect( lambda f: self.editor.setFontFamily(f.family()) )
But yes, after saving and re-loading from HTML I see the problem you mean – the file loads with the formats intact, but you can’t change the font anymore. I think these two things might be related, and loading from HTML is leaving the editor with fonts set on all the text that don’t relate to the system fonts – i.e. Qt isn’t properly re-interpreting them to the system fonts when converting from HTML to “rich text”. I’ll keep digging.
Yes, I’ve tried on linux with pyqt version 5.9.2 and it seems to work properly.
Just for curiosity which operating system are you using?
I’m working on Windows 10
There seems to be an error in the copy paste of images. The code should be like;
elif source.hasImage(): image = source.imageData() uuid = hexuuid() document.addResource(QTextDocument.ImageResource, QUrl(uuid), image) cursor.insertImage(image) return
I further investigated the problem and looks likt removing this line:
i can update the font family. Re-enabling that signal-slot connection BUT changing the “block signal” for excluding the fontComboBox i can stil change the font family.
Looks like a problem in enabling/disabling signals…