PyCharm seems to expect wrong type
I'm currently learning to create graphical applications using Qt with PyQt bindings. PyCharm has been a great help getting to grips with a lot of new programming stuff in the past few years, but I've run into this thing that doesn't make sense to me. Following a tutorial, I started with the following class:
class Example(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
QToolTip.setFont(QFont('SansSerif', 10))
PyCharm notices two errors here: on the third line, super().__init__(), it seems to expect the parameter 'flags'. The program runs fine when I instantiate an Example, though.
But here's the one that I really don't understand and why I posted: It's the last line. PyCharm seems to think that QTooltTip.setFont() expects a type QToolTip as first argument, but it obviously gets a QFont so it tells me there's something wrong. Now when I rightclick on setFont and go to its declaration, I see the following:
def setFont(self, QFont): # real signature unknown; restored from __doc__
""" setFont(QFont) """
pass
It looks like my code (a QFont) is exactly what the function expects, so why does PyCharm think QTooltip.setFont() expects a QTooltip argument?
Is there something I'm doing wrong? A setting I'm missing?
请先登录再写评论。
Hi there!
It looks like we failed to detect that methods of QToolTip are supposed to be called as static methods rather than instance methods. Because in Python it's possible to provide value of "self" argument explicitly, like in "str.upper('foo')", we are expecting two arguments for "QToolTip.setFont()": a QToolTip instance followed by an instance of QFont and thus report that false error.
There is an existing issue in our tracker about this problem. Thanks for reminding us of it, we will try to fix it sooner.
I see, thanks for the explanation and the quick response. Good luck with further development, hopefully JetBrains sticks around for a while - I'm always amazed at the quality you guys put out - the IDEs are second to none in their category. :)