Qt4/pyqt4 - Can Not Set The Default Font For Qtextdocument
My code is like this: from PyQt4 import QtGui doc = QtGui.QTextDocument() d_font = QtGui.QFont('Times New Roman') doc.setDefaultFont(d_font) cur = QtGui.QTextCursor(doc) cur.inse
Solution 1:
I can see the same behavior on my Ubuntu Oneiric box with PyQt4.8.5. I don't think it is a bug. The font of the written text depends on the font of the cursor used to write the text.
The following should work for you:
from PyQt4 importQtGuidoc= QtGui.QTextDocument()
cur = QtGui.QTextCursor(doc)
d_font = QtGui.QFont('Courier')
c_format = QtGui.QTextCharFormat()
c_format.setFont(d_font)
cur.setCharFormat(c_format)
cur.insertText('sample text')
writer = QtGui.QTextDocumentWriter()
writer.setFormat(writer.supportedDocumentFormats()[1])
writer.setFileName('CV')
writer.write(doc)
I've used Courier because Times New Roman is not installed on my system.
Post a Comment for "Qt4/pyqt4 - Can Not Set The Default Font For Qtextdocument"