[Solved] Recommendations for learning GTK4 UI creation in Debian

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
Onsemeliot
Posts: 351
Joined: 2010-12-15 14:43
Has thanked: 23 times
Been thanked: 9 times

[Solved] Recommendations for learning GTK4 UI creation in Debian

#1 Post by Onsemeliot »

I have just completed a course on programming with C++. (Unfortunately, we did almost exclusively use the command line and only very briefly did extremely basic UI examples using Qt Creator. And since I prefer the look and feel of GTK+ over Qt I thought I should better learn how to create interfaces I do actually prefer.) Therefore, I want to create my first own small C++ project using GTK4. To get there, I try to work my way through the official gtkmm documentation. Unfortunately, in chapter 17 I discovered that Debian stable includes gtkmm 4.8 while some examples in the documentation need at least version 4.10 to work.

I usually try to stick with the versions provided by Debian stable to keep everything reliable and simple. But since I am learning something new it doesn't seem sensible to start with learning a deprecated standard.

According to my findings before GTK4 Glade was the go-to solution for creating user interfaces with GTK+ but at the moment development looks like a transitional state where Glade isn't really workable with GTK4 applications and Cambalache doesn't seem to be ready for general use yet. (So far it isn't part of Debian anyway.)

I am surprised how hard it is for me to understand gtkmm. I am not sure if my current approach of trying to learn to write all necessary code for GTK4 using gtkmm by hand is a sensible approach. I have already encountered examples where I failed to adapt or combine functions from different examples. (I can't even predict what methods and properties I should expect in Glib or GTK.) I am clearly missing some foundational understanding on how concepts in GTK do really fit together and muddle through trying to understand as much as possible on the way. This isn't an approach I feel very comfortable with. Maybe I am wasting a lot of time by messing with things I shouldn't even attempt yet. Maybe GTK was not the best choice to be used in my first C++ project because it is tailored towards C and since gtkmm is only a wrapper for C++. But I have already invested weeks in it and at least by now it is probably less confusing if I stick with it.

On YouTube I found someone who seems to have found a way to still use Glade to create GTK3 UI files which he then converts to GTK4. If possible I would like to avoid such a workaround.

I wonder how you experienced developers out there would approach this hurdle. Do you figure it would be sensible for me as a C++ beginner to switch to Debian testing and at least get gtkmm version 4.10? Would you recommend compiling Cambalanche from code and start working with it right away? Do you know of any more basic guide for learning GTK4 GUI development with C++? Unfortunately, my track record of resolving issues by consulting the GTK documentation has not been great so far because without examples I rarely understand how exactly properties and methods even need to be written in code.
Last edited by Onsemeliot on 2024-06-09 14:02, edited 1 time in total.

juribel
Posts: 23
Joined: 2024-03-03 06:30
Location: Rheinland, Germany
Been thanked: 8 times

Re: Recommendations for learning GTK4 UI creation in Debian

#2 Post by juribel »

Can't actually help with gtkmm. I use Perl as my favourite programming language and there are a couple of tutorials and sample programs for GTK available in the internet. Recently, being frustrated and confused by the official documentation, I eventually asked chatGPT how this and that works and it almost always gave me well explained and running example programs. Just ask chatGPT "linux what is gtkmm". With this question (asked in German), it gave me a sample program of about 50 lines written in C++ with good explanations in English. As I don't use C, I did not try to compile it.

I used glade as a GUI builder before, but for writing small tools it is way too rich and complicated and several items seem to be missing. I found it not necessary to use such tools. Writing the source code by yourself is easy enough (at least in Perl 8) ) For me, the problems in writing GTK applications was not that much GTK itself but rather how to handle the event driven logic.

User avatar
Onsemeliot
Posts: 351
Joined: 2010-12-15 14:43
Has thanked: 23 times
Been thanked: 9 times

Re: Recommendations for learning GTK4 UI creation in Debian

#3 Post by Onsemeliot »

Thank you for your insights juribel. Really, you use Perl? I think I have never met someone who actually still uses it.

I'm not especially happy about many aspects of ChatGPT. So I don't think I am yet at the end of the rope where I might consider using it as kind of a last resort.

I am still confused about the official documentation of gtkmm. There are examples where they provide the code for a very simple XML file that details an image resource for an app icon. But they don't link it anywhere in the code examples. And therefore I am not surprised that it doesn't work. But the path to the same (not existing) image file is linked in the code directly too. I tried linking to an existing icon file using a relative or absolute path. Nothing seems to work. I just don't understand how it is even supposed to work. I can compile the program without issues but when I run it I always just get the error that the resource wouldn't exist. (The program runs just fine if I comment out the line with the image link.) But I get that this is the wrong community to ask about this ...

juribel
Posts: 23
Joined: 2024-03-03 06:30
Location: Rheinland, Germany
Been thanked: 8 times

Re: Recommendations for learning GTK4 UI creation in Debian

#4 Post by juribel »

Well... Perl is alive and well, and it does what I expect it to do. No reason to leave it. For me, it has been one of the silliest ideas being forced to use indentation instead of braces like Python does.

I understand your confusion with gtkmm very well. For me, using chatGPT does not feel like "end of the rope". Like you, I simply felt helpless with the official docs explaining the object hierarchy and such rather than providing well-explained examples. That's just what chatGPT does for me and what I use it for. In this case, it really is very easy to verify if it tells the truth :-)

User avatar
Onsemeliot
Posts: 351
Joined: 2010-12-15 14:43
Has thanked: 23 times
Been thanked: 9 times

Re: Recommendations for learning GTK4 UI creation in Debian

#5 Post by Onsemeliot »

juribel wrote: 2024-06-04 08:14Perl is alive and well, and it does what I expect it to do. No reason to leave it.
I totally understand. I never got into Perl and learned PHP instead. Since it also did what I needed I wasn't tempted to try Perl. And it seems PHP is rather hated almost everywhere – except from those who just use it. ;)
chatGPT ... is very easy to verify if it tells the truth
Sure, but I don't want to confirm the proposed role of this project by using it. From my view it is even more a dependency trap and privacy nightmare than proprietary software.

Back to the original subject: It seems this is not the place where C++ developers using GTK do hang out. ;)

User avatar
Hetzer
Posts: 94
Joined: 2024-01-05 22:30
Location: /etc/fstab
Has thanked: 70 times
Been thanked: 31 times

Re: Recommendations for learning GTK4 UI creation in Debian

#6 Post by Hetzer »

From user perspective, I'd recommend to not go with GTK4 as it's GNOME-centric and most things built on it look out-of-place basically everywhere but GNOME.
There are GTK-styled themes available for both Qt5 and Qt6, at least in Debian repositories (i.e. qt5-gtk-platformtheme), so it feels same as GTK+ and plus to that, as you probably already know, Qt works with C++ natively.
Maybe it's worth looking into Qt again?
Listen carefully because I'll say it only once.

User avatar
Onsemeliot
Posts: 351
Joined: 2010-12-15 14:43
Has thanked: 23 times
Been thanked: 9 times

Re: Recommendations for learning GTK4 UI creation in Debian

#7 Post by Onsemeliot »

Thank you for considering my questions, Hetzer.
Hetzer wrote: 2024-06-05 06:26I'd recommend to not go with GTK4 as it's GNOME-centric and most things built on it look out-of-place basically everywhere but GNOME.
I noticed that also Qt applications (like Scribus for example) look very out of place in GNOME. From that perspective there doesn't seem to be a real difference. (Or should I try to find out how to use the GTK-styled Qt themes you mentioned?)
There are GTK-styled themes available for both Qt5 and Qt6 ... and plus to that, ... Qt works with C++ natively. Maybe it's worth looking into Qt again?
From a strategic standpoint Qt indeed seems to be the safer bet – at least for now if I want to create programs that do work well outside of GNOME. On the other hand I am not confident that I will be able to contribute relevant programs soon. So it seems more likely that I might help out with small things in programs I already use and know. And since I have been using GNOME (and LXDE on older devices) for many years I am most familiar with GTK applications.

I fear I still have a long way ahead before I can actually contribute anything useful as a programmer. I have just started with C++ and I have no practice outside of simple command line training programs. I also still have a wealth of books I want to work through. And I think I should get familiar with well established design patterns early on. At the moment my biggest problem is understanding other peoples code well enough so that it gets feasible to overcome the limitation of my own tiny comfort zone. Unfortunately, it is exactly reading other peoples code that is often recommended to actually learn sensible approaches. And it also is what I need to do when following the gtkmm documentation because the approach there doesn't seem to be explanations but getting me used to how things are done. I guess in this way it is similar to modern natural language learning. I am not convinced that it works, but maybe I am just to old school like the people who insist on learning grammar when our brain mostly actually finds and internalizes patterns without us even consciously understanding them ...

User avatar
Hetzer
Posts: 94
Joined: 2024-01-05 22:30
Location: /etc/fstab
Has thanked: 70 times
Been thanked: 31 times

Re: Recommendations for learning GTK4 UI creation in Debian

#8 Post by Hetzer »

Hetzer wrote: 2024-06-05 06:26 There are GTK-styled themes available for both Qt5 and Qt6 [...]
Eh my bad here, It's not a theme but rather a "middleware" translating GTK themes for Qt, I think...
Onsemeliot wrote: 2024-06-05 17:12 (Or should I try to find out how to use the GTK-styled Qt themes you mentioned?)
I think it's worth a try, it's not hard to do so.
In my case I did install qt5-gtk2-platformtheme and qt5ct, exported QT_QPA_PLATFORMTHEME=qt5ct variable, logged out and in, opened qt5ct and set "Style" and "Standard dialogs" to gtk2 and for icons go to "Icon Theme" tab and selected my icon set... And de-facto that's all.
Results:
Greybird-dark GTK theme
Greybird-dark GTK theme
Adwaita theme
Adwaita theme
Both with GNOME Wine icon theme
Onsemeliot wrote: 2024-06-05 17:12 From a strategic standpoint Qt indeed seems to be the safer bet – at least for now if I want to create programs that do work well outside of GNOME. On the other hand I am not confident that I will be able to contribute relevant programs soon. So it seems more likely that I might help out with small things in programs I already use and know. And since I have been using GNOME (and LXDE on older devices) for many years I am most familiar with GTK applications.

I fear I still have a long way ahead before I can actually contribute anything useful as a programmer. I have just started with C++ and I have no practice outside of simple command line training programs. I also still have a wealth of books I want to work through. And I think I should get familiar with well established design patterns early on. At the moment my biggest problem is understanding other peoples code well enough so that it gets feasible to overcome the limitation of my own tiny comfort zone. Unfortunately, it is exactly reading other peoples code that is often recommended to actually learn sensible approaches. And it also is what I need to do when following the gtkmm documentation because the approach there doesn't seem to be explanations but getting me used to how things are done. I guess in this way it is similar to modern natural language learning. I am not convinced that it works, but maybe I am just to old school like the people who insist on learning grammar when our brain mostly actually finds and internalizes patterns without us even consciously understanding them ...
Wishing ye good luck, mate!
Listen carefully because I'll say it only once.

User avatar
Onsemeliot
Posts: 351
Joined: 2010-12-15 14:43
Has thanked: 23 times
Been thanked: 9 times

Re: Recommendations for learning GTK4 UI creation in Debian

#9 Post by Onsemeliot »

I think I will at least install Debian testing to work with the newer version of gtkmm. I am already doing a backup of the old system. Because it is an old device it takes quite a while. I think with the new install I will go for GNOME right away because I will need GTK4 and it doesn't seem to make much sense to install LXDE (GTK2) to make it light weight and then add GTK4 afterwards. For learning how to work with GTK I will probably just need patience. A shortcut doesn't seem to exist.
Update:
I did install Trixie and so far I can't complain. My old laptop seems to be perfectly capable of running GNOME in a satisfactory manner. And the newer GNOME in fact does offer a more polished interface too. :D

Post Reply