Skip to content

[Solved][PySide] TypeError: 'PySide6.QtGui.QFont.setWeight' called with wrong argument types: PySide6.QtGui.QFont.setWeight(int)

Last Updated on 2021-11-08 by Clay

Today when I want to convert the old PyQt5 project into PySide6, I got an following error message:

TypeError: 'PySide6.QtGui.QFont.setWeight' called with wrong argument types:
  PySide6.QtGui.QFont.setWeight(int)
Supported signatures:
  PySide6.QtGui.QFont.setWeight(PySide6.QtGui.QFont.Weight)


The interface is make by Qt Designer, and use PyUIC convert into PyQt5 code, the QFont use setWeight(INT) method to adjust the font thickness. However, obviously this method is not accepted in PySide6.

As the error message shows, PySide6 supports the use of the QFont.Weight property.


Solution

Check the PySide6 QFont class, you can see the following program:

def setWeight(self, weight): # real signature unknown; restored from __doc__
    """ setWeight(self, weight:PySide6.QtGui.QFont.Weight) -> None """
    pass



It means that in PySide6, you can only use the default name to adjust the font:

ConstantValueDescription
QFont.Light2525
QFont.Normal5050
QFont.DemiBold6363
QFont.Bold7575
QFont.Black8787

In other word, if you suppose you want your font to be regular bold, then you can use the following code:

QFont.setWeight(QFont.Bold)


But if you want to use the INT value to adjust the font weight as before, you may consider using setLegacyWeight() to assign the value. This is just like the name of the method, you can directly set the INT value data just like the original PyQt5.

QFont.setLegacyWeight(75)

References


Read More

Leave a ReplyCancel reply

Exit mobile version