How to get PyCharm to recognize PyQt5 signals?
已回答
I'm running PyCharm 2017.2.3 Community Version.
I created a new project and created a VirtualEnv for it from within PyCharm. I also installed PyQt5 from the Project interpreter settings tab. When I try to connect a signal to an event, PyCharm can't find the reference for the signal. If I run the code from the Run menu or the green arrow button the application works correctly, so the issue is not with the code.
Here's an example code that runs correctly but PyCharm says it can't find reference for the clicked signal:
import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QCoreApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
btn = QPushButton('Quit', self)
# PyCharm can't find reference for `connect`
btn.clicked.connect(QApplication.instance().quit)
btn.resize(btn.sizeHint())
btn.move(50, 50)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Quit button')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
What can I do to get PyCharm to correctly recognize the signal? I already tried invalidating caches & restarting.
请先登录再写评论。
Unfortunately, it's a known problem, please check https://youtrack.jetbrains.com/issue/PY-24183 and related issues and follow them for updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.
Just commenting that I'm also having this issue on Pycharm 2018.1.1 CE when using PyQt 5.10.1
This Linked issue https://youtrack.jetbrains.com/issue/PY-22908#tab=Comments seems to have a workaround for editing the stubs, but I'm yet to figure out how to do that