L
L
legion882017-03-17 00:58:04
Python
legion88, 2017-03-17 00:58:04

PyQt5 - why does not determine the font size?

Why is the text font size incorrect?

text = self.secret.toPlainText()
font3 = QtGui.QFont(text)
fontinfo = QtGui.QFontInfo(font3)
self.answer.setText(str(fontinfo.pointSize()))

It is necessary to insert text into one TextEdit1 with one font size, except for one letter. Parse the text, check if the font of a certain size is included in TextEdit1 and display True or False in TextEdit2.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey6661313, 2017-03-17
@legion88

in pyqt5, Qstring was cut out and they think that str is better suited for this business .... toPlainText() returns str and even without a format (i.e., it just displays what is visible on the screen):

print (type(text))
<class 'str'>.

from which it is pointless to recognize the font.
I see the only way out is to use toHtml()
something like this:
from PyQt5 import Qt
app = Qt.QApplication([])

textEdit = Qt.QTextEdit()
textEdit.show()

secret = "<H4>test<H2>L, <H3>L"
textEdit.setText(secret)

html = textEdit.toHtml()
td = Qt.QTextDocument()
td.setHtml(html)

formats = td.allFormats()
print(formats)

app.exec_()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question