Help my Kirigami application install under KDE and use a custom window icon

I recently spent a few days creating a Kirigami front-end for my textual food diary, in order to learn about KDE development. I’ve made a lot of good strides in my understanding and it’s good enough for my use now, except for two problems:

  • Google AI isn’t giving me the correct code to change the default Wayland window icon to my own icon
  • I would like to understand how to “install” my application on KDE once it is built

I am running EndeavourOS, if that matters. Any help is appreciated!

Code is hosted on GitHub: https://github.com/aorliche/kfooddiary/

FWIW, here’s my icon and a few screenshots:

logo

Editing a single day:

Search for workout days:

Graphs of calories and body weight over time:

An aside: I’ve made good use of the documentation and tutorials available on the KDE website, however, I would have gotten nowhere if not for the Google Search AI patiently explaining for me how various parts of Qt and Kirigami work together.

The very first page of the Kirigami tutorial is explicit about how to do this.

You need to use a CMake install() call for the target executable and for the desktop file, and after building manually, you run the cmake --install command.

Thanks for the info! I did not see any mention of installation in the Kirigami tutorial.

Any idea about how to change the app icon from the default Wayland one?

I was finally able to figure everything out. You can’t set a window icon in Wayland unless the app is installed into system directories, whereupon the icon is determined from your .desktop file. You need to create a desktop file (ask Google) and an .svg icon, then edit the cmake files to install the icon file. My cmake setup (from the KDE tutorials) already included a line to install the desktop file. These are the relevant lines from my top-level CMakeLists.txt:

install(PROGRAMS org.kde.kfooddiary.desktop DESTINATION ${KDE_INSTALL_APPDIR})

install(FILES src/icons/org.kde.kfooddiary.svg 
        DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/hicolor/scalable/apps)

And here is the .desktop file:

[Desktop Entry]
Name=KFoodDiary
Comment=A text-first app for managing and recording calories, weight, and other daily events
Exec=kfooddiary
Icon=org.kde.kfooddiary
Type=Application
Terminal=false
Categories=Utility;

I first tried to get the program to install into $HOME/.local, but plasma did not display the icon correctly when searching for the app, so I installed it under /usr.

Hope this helps someone who is similarly confused!

Aha, I missed that you wanted to install a custom icon. That’s correct, if you don’t install the icon to the icon theme location it won’t be found. This is taught later in the tutorial but I should add this information earlier.

It should have worked in ~/.local though, I’ve done extensive testing before switching to ~/.local in the docs, I’ll check it out.