Issue
I have the following line in my code:
self.textLength = self.fontMetrics().width(self.text())
It works with PyQt5, but I'm trying to move the code to PySide6, and when I do I get the error AttributeError: type object 'PySide6.QtGui.QFontMetrics' has no attribute 'width'
I've tried reading through the QFontMetrics docs, but everything I do seems to give the same error. Any ideas of how I can convert this line to PySide6? Thank you!
Solution
QFontMetrics.width()
has been considered obsolete since Qt 5.5 and deprecated from Qt 5.11 (but will probably be still supported throughout any future releases of Qt 5), and eventually removed in Qt 6.
As the documentation (which already is in the obsolete members page of Qt5) reports, the results of width()
were inconsistent and unreliable in many situations, mostly because it didn't consider the letter bearings.
You should use horizontalAdvance()
or boundingRect()
.width()
.
Answered By - musicamante
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.