pythonvisual-studio-codesyntax-highlightingpyside6

Missing syntax highlighting in VS Code for 'clicked' method of QPushButton


I am designing a program in Python 3.7.9 based on the PySide6 6.3.2 library in VS Code.

This program contains several buttons as QPushButton, which are connected to functions as such:

prev_button.clicked.connect(go_to_prev)
next_button.clicked.connect(go_to_next)

My problem is that the clicked method, while fully functional and working, isn't being properly highlighted.

I have installed the Python and Qt for Python extensions in VS Code. All other methods of QPushButton are being colored properly, it's only the clicked function that fails to highlight (that I'm aware of). When I type e.g. next_button. and view the suggestions that pop-up, click is among them which I presume simulates a button click, but not clicked.

Here's an example function:

import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton

def button_clicked():
    print("Button clicked!")

if __name__ == "__main__":
    app = QApplication(sys.argv)

    window = QMainWindow()
    window.setWindowTitle("Simple GUI Example")

    button = QPushButton("Click me!", window)
    button.clicked.connect(button_clicked)
    button.setGeometry(50, 50, 100, 30)

    window.show()

    sys.exit(app.exec())

and what I see on my screen using the default VS Code dark theme:

enter image description here

Note that the setGeometry method is being highlighted, but not clicked.connect.


Solution

  • I was able to resolve this by installing the PySide6-stubs library from pip:

    pip install PySide6-stubs
    

    The highlighting now appears correctly:

    Python code showing highlighting for button.clicked.connect