QML syntax support
PyCharm provides syntax support in .qml files for both Qt5 and Qt6. Find below a few examples of QML code insight features.
Highlighting and code completion for QML types and properties:
Find Usages for QML symbols can be invoked by pressing AltF7 or clicking the hint in the editor:
In the usages popup you can navigate between them and tune the search ():
Another navigation option is Structure View for the file contents. To open it, press Alt07 or select View | Tool Windows | Structure from the main menu:
Quick Documentation popup is also available for QML symbols. Invoke it by hovering over a symbol or by pressing Ctrl0Q:
Go to Settings | Languages & Frameworks | QML and set the Enable QML language server checkbox.
This option enables QML-specific code inspections if there are
qmlls
components installed.Enable Use completion from QML language server to get language-server-based completion suggestions for QML symbols instead of those provided by PyCharm.
Go to Settings | Languages & Frameworks | QML.
In the Extra QML imports field, provide the path to the directory containing additional QML modules.
note
Make sure to set the relative path, not the path to the module itself.
For example, if you specify .
/bin/ here, then an import statement likeimport MYLIB
will search for the ./bin directory./MYLIB
You can use the IDE settings or qmlformat to configure code style for QML.
By default, qmlformat is disabled and PyCharm uses the built-in code style settings. To access them, go to Settings | Editor | Code Style | QML:
To quickly access the settings, select Configure Indents for qml QML in the bottom status bar switcher:
To enable qmlformat, use the status bar switcher (see above) or go to Settings | Languages & Frameworks | QML and set the Enable 'qmlformat' as formatter checkbox.
note
Qmlformat overrides the IDE code style settings.
When qmlformat is enabled, its indicator is shown in the bottom status bar. You can also disable qmlformat from there:
Follow the steps below if you get the editor notification indicating that PyCharm could not find the Qt installation path or QML imports directory:
Check that
CMAKE_PREFIX_PATH
points to the Qt installation directory.Click CMake settings and add the following to CMake options:
-DCMAKE_PREFIX_PATH=your_qt_installation
For example:
In most cases, configuring CMake is enough for PyCharm to detect Qt and QML paths, however, if the notification is still there, you might need to set the paths manually. Click QML settings or go to Settings | Languages & Frameworks | QML to do so.
QML support is PyCharm is currently a work in progress. The list of known issues include:
Thanks for your feedback!