Search code examples
c++qtcmakeqt-creator

Group .ui files in project tree when using CMake


I have a simple gui project in QtCreator, which consists of several .cpp .h and .ui files and using CMake as a build system.

The problem i face is that .ui files, as oposed to .cpp and .h files, aren't grouped under corresponding header in project tree. They are just shown on the same level as .cpp and .h headers (see picture below).

enter image description here

I had no such problem when i was using qmake as a build system. I can totally live with that, but it can get really annoying as the project grows. Is there a way in QtCreator to customize appearance of a project tree?


Solution

  • You can use source_group in your CMakeLists.txt to group *.ui files as a source group in QtCreator or another IDE

    file(GLOB_RECURSE UI_SRC "*.ui")
    source_group("Ui Files" FILES ${UI_SRC})
    

    This also works for .qml files for example.