Question about QApplication.fontMetrics() in PyQt6

Florian Bruhin me at the-compiler.org
Wed Jan 13 07:43:54 GMT 2021


Hey,

On Tue, Jan 12, 2021 at 11:13:36PM +0800, RedHuli wrote:
> This is a simple question I have about using QApplication.fontMetrics() in
> PyQt6. When I used it before in PyQt5, I never received an error message.
> However, when I want to get the font metrics I now get the error :
> 
> font_size = QApplication.fontMetrics() # Calculate the size of the text
> 
> 
> AttributeError: type object 'QApplication' has no attribute 'fontMetrics'
> 
> I am reimplementing the sizeHint() method when subclassing
> QStyledItemDelegate.

Looks like it's marked as obsolete in Qt 6:
https://doc.qt.io/qt-6/qapplication-obsolete.html

Looks like this is the recommended replacement:
https://doc.qt.io/qt-6/qfontmetricsf.html#QFontMetricsF

Florian

-- 
            me at the-compiler.org | https://www.qutebrowser.org 
       https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
       GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
             I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210113/ef04dea4/attachment.sig>


More information about the PyQt mailing list