Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
GTK4 for Graphical User Interfaces (ssalewski.de)
160 points by chauhankiran on Jan 3, 2021 | hide | past | favorite | 75 comments



The full title appears to be "GTK4 for Graphical User Interfaces with the Nim Programming Language", so putting in a reference to Nim in the HN title might be a good idea.


Agreed. Interestingly, there's a dead comment saying much the same thing.


Upvoted and flagged to get Dang's attention. Hopefully mods will will notice and edit the title. Will unflag soon.

Unflagged.


Thank you for your service.


> "GTK4 for Graphical User Interfaces with the Nim Programming Language"

And it is outdated, as there would be no GTK4 - instead it would be released as GTK40, so some API could be changed and samples from this book would not work anymore.


You're confusing GTK with GNOME.


As a supposedly guide to writing app, the introduction reads more like an opinion piece.

The author has a very anti-C stance to say the least. For an article about writing UI, it spends a lot of time laying out all the short-coming of using C to build a UI toolkit.

Amusingly, Qt is mentioned as initially not having a FOSS license but "now available in version 6 with much less restricted licenses"... that's quite a weak praise given that it is available as LGPL, GPL or commercial non FOSS licensing. He then goes on criticizing Qt for being bloated. Most people would rather say that is very feature-rich. Qt is also modular. You don't need to include libraries you don't use.

English does not seems to be the author native language; there are many bad choices of word, like saying that C in "restricted"; I think he meant it is "limited".


> "now available in version 6 with much less restricted licenses"... that's quite a weak praise given that it is available as LGPL, GPL or commercial non FOSS licensing.

I was already writing UI applications with an LGPL licensed Qt 4.x, so the version 6 hasn't changed in that regard, just like version 5 didn't change either. And I'm sure Qt was already FOSS in earlier versions, but 4 and 5 are the ones I can confirm having FOSS licenses.


From memory version 2 is the one that moved to gpl and this happened before 2001.

So this is reheating a 20 year old talking point.


IIRC Qt now requires registration to download their releases. And some drama around how frequently OSS releases would get updates.


> IIRC Qt now requires registration to download their releases.

not if you use it throuh vcpkg or https://pypi.org/project/aqtinstall/ or your distro's package manager or mingw or...


Aren't these all downstream sources, and therefore may lag or fork?

IME it used to be possible to anonymously get binaries and sources from Qt themselves.


aqt uses the upstream qt repos


Qt3 was GPL (or commercial); with Qt4 LGPL option was added.


Qt seems to use less memory compared to gtk in my experience (not qtquick though)


I saw that, and am still amazed at how much effort they poured into that. They are beating GTK 2.0 here.


Qt is fully open source since 2000 and nowadays most of the components are lgpl3. I'm still sad that some people are spreading so much fud about it 20 years later. Same with the bloated thing, people complained that qt and kdelibs were bloated and now that qt and the kde frameworks are modular they complains about too much librairies.


> Qt is fully open source since 2000

Not fully; only the X11 and embedded version was open source (GPL). The Windows version was only available under a commercial license until 2005. Because of GPL I had to pay for a commercial license for three platforms until 2008. LGPL became available in 2009.

> I'm still sad that some people are spreading so much fud about it 20 years later

It is not exactly the case that the Qt Company clearly points out to users that they can use Qt free of charge under LGPL; rather the opposite seems to be the case. I know various people who primarily bought a commercial licence because they did not consult their own legal advisor and instead followed the recommendations of the QTC sales people.


> I know various people who primarily bought a commercial licence because they did not consult their own legal advisor and instead followed the recommendations of the QTC sales people.

To be fair, if they weren't willing to put in the relatively small amount of effort required to find out how it was licensed, they can clearly affort to pay for the commercial license and if that's true, they probably should do so anyways in order to fund its development.

And yes, I know a very similar argument can be made for horrible dark patterns like the crap TurboTax in the US pulls, but B2B and B2C are very different situations (power imbalance).


> if they weren't willing to put in the relatively small amount of effort required to find out how it was licensed

That's not the point. They are single developers or start-ups not used to match what they intended to develop with the LGPL license terms. Their primary mistake was to trust the sales guys. I had personal contact with some of them, and in no case was a commercial licence objectively necessary. Sure, it's not the only way inexperienced people get ripped off, but it doesn't help confidence and clarity, which is what this thread is about.


Just yesterday I was reviewing Qt, GTK and Electron as possible choices for some GUI exercise, and _at a glance_ Qt sure looks likely to involve committing to GPL, which is a pretty irreversible commitment to have to make at the outset of a project.

I guess it's possible to sort through the individual components and find a subset that is LGPL and not GPL, but that's a lot of work, especially if you're not familiar with Qt already and need to make a decision.


If you link properly, GPL isnt a problem: https://news.ycombinator.com/item?id=23321448


You seem to mix that up with LGPL. With GPL the linked app also becomes GPL. With LGPL this is not the case; usually apps link to Qt dynamic libraries which is ok.


I guess that would work, the time and effort involved in getting end-users to link the application makes downloading a large Electron binary seem downright pleasant.


You can just ship your application with a dynamically linked Qt library file(s). There is no extra step for the user.


This is about LGPL


Correct, although LPGL is the primarily relevant one for Qt. Only a few relatively niche parts of it are under GPL.


From a C or Nim programmer's perspective any C++ project can appear bloated so perhaps that was a part of what he was trying to say.


I realize this is an article about GTK, but the author is really not selling it. It opens with an explanation that GTK is pretty much not maintained. Later, it's compared to Qt:

> The advantage of Qt is that it is active developed and supports all important operating systems including the mobile Android and iOS systems with a native look and feel.

These feel...like important things for your application framework to support. Qt's "bloat" is listed as the only major disadvantage, but only after lamenting GTK's own bloat.

> For many Windows or macOS users GTK has the disadvantage that GTK draws all it widgets itself, it does not use the native graphical elements of the proprietary systems. GTK allows theming by use of cascading style sheets (CSS) so it can be tuned to look not too strange on Windows and macOS, but look and feel generally does not really map to native apps.

Personally, this is one of the worst disadvantages of GTK for me, and makes me cringe when I see an app using GTK's default styling. Even Electron (also lamented for its bloat) does "native" controls by default.

There's really got to be a better argument for using GTK than "it's less bloated and is written in C"


Uh ok. Gtk is maintained and he only said it has few maintainers.

Calling the adwaita theme “cringey” seems silly to me. The latest Mac default style is very similar. Windows “native” look and feel is a joke. A ton of popular apps don’t care about native look anyways they just want their branding.

Qt just tried to pull some crap again with their licensing too.

I appreciate the author because I like nim and gtk development. He even fixed an issue for me last year when I was trying these bindings out.

I don’t agree with his slightly pessimistic view though. There are a lot of new people learning it right now spurred by the new phones and mobile Linux desktop ends.

It’s true the main appeal is to people who like their default styling and the gnome desktop


It's great that the author promotes both Nim and GTK4, which, in my opinion, are both great opensource projects. But I think the author should make it clear that he disabled text anti-aliasing for some reason. A lot of people in this thread are complaining how bad the text rendering is. As someone who uses GNOME (build with GTK) for years, I want to make it clear: GTK supports both anti-aliasing and hinting. The text rendering looks great! It's really just one web search away to check the effects.


> Unfortunately GTK is currently not in a very active state. There seems to be one or two paid full-time developers which try to finish official release 4.0 and a few volunteers which support the development.

Really selling it there. If I'm going to learn a thing the last thing I want to hear is "dead project"


It’s not dead. Yes development is slow but there is the foundation which had a few paid devs and red hat pays some people too.

Mostly it just means the scope of future plans for the project remains narrow


he is not trying to sell/convince you to learn gtk. he is warning if you already want to learn it. not everything posted on hn should be a promotion material.


After working with a wide range of windowing libraries (from raw win32 and x11 to Tkinter, Wx and Qt), I've finally landed on and am staying with qt. It does pretty much everything better than all the other windowing libraries.


I had not looked at Nim before, but certainly will do. If anything, GTK is lacking a bit HOWTOs, which give the beginner a guide, which APIs to use for a certain task. So I will give this a good look. Personally, I have used GTK from Go, which also is a nice match for the API.


The text rendering seems very poor. Is that an artefact of the font used, the platform or something else?


It's due to his system settings. This is how text looks like when you have all antialiasing disabled in fontconfig.


I noticed that the mouse cursor is bigger than mine. It could be due to using fractional scaling on a high-DPI monitor, making subpixel artifacts a bit glaring?


There’s a setting in the appearance control panel.


Looks like it's rendered by Asciidoctor.


Oh, did they drop the "+"? The name used to be "GTK+" but that seems to have changed. Does anyone know when?



Thanks! I have been using GTK since the late 90s (1.x versions) but dropped of the devel list a few years ago due to lack of time/focus/interest.

Would love to port my pet project to 4.x. :)


Wait, GTK was spun out of GIMP?


Yes. GIMP used to use the proprietary Motif toolkit before, and GTK was created to get rid of this dependency.

The Linux logo was created on a Motif version of GIMP (see screenshot):

https://isc.tamu.edu/~lewing/linux/notes.html


Well, GTK means GIMP Tool Kit, so yes.


Yes and the GIMP devs are still hard at work trying to make GIMP use GTK 3... (beta recently released)


The name is short for "gimp tool kit", yes


Can't help but think a lot of code is needed here just to render some controls on a window.

Something like XAML for GTK would be nice.


It exists, it's GtkBuilder[1]. There's also a tool to create those XML files, Glade[2] (needs to be updated for Gtk4 but...)

1. https://developer.gnome.org/gtk4/stable/GtkBuilder.html

2. https://glade.gnome.org/


There is Glade. But some GNOME people seem to recommend against using Glade?

https://blogs.gnome.org/christopherdavis/2020/11/19/glade-no...

I have used GTK several times, but Qt always felt far more pleasant. Plus Qt applications work well on Windows and macOS, whereas GTK renders extremely slowly on macOS and looks and feels very non-native on Windows and macOS.


I think Qt is generally superior. Still, I find GTK easier to get my head around (though I don‘t work regularly with either). Also, as a vanilla Ubuntu user, GTK apps look better on my system.


From the link you provided, it seems Glade is not recommended because there exist better alternatives (in the view of the Gnome project, I can't comment on it).


The alternative is to use... some pen and a paper?

> . If you need to mock something up, you can try sketching on a piece of paper or using our mockup resources.

Linux GUI is honestly in a bizarre state. And the Gnome team seems to keeping on recommending against the tools they developed themselves (Vala...). Seems like QT is the best alternative...


This is why I like Qml so much, it is using an declarative ui language while having a nicely organized cpp code for the backend. But as far as I know GTK also have some xml files for the ui.


This is nothing compared to something like the Win32 API.

More importantly, this sort of code is incredibly simple and linear with virtually no logic or state, this is the worst sort of code to try and code golf into something more "elegant", you just end up with something more complicated but less flexible.



#qt4ever

https://www.youtube.com/watch?v=gGZyVSOnqm0

The tl;dw: Kernel guys made a scuba diving app, using C + GTK. They switched to C++ and QT, due to issues/poor quality of GTK, bad attitude by GTK. QT also fixed a lot of complaints they had about C++. Also QT looks like native application on other platforms.


I remember using pidgin (then called GAIM) on windows and having it fit right in visually, and that's a GTK2 app. It became slightly more noticeable on Windows 7, where UI animations that were present in the Windows UI would be absent due to, I believe, GTK2 not having a proper animation library, but it still looked like a native app. No idea if that's still the case for GTK3 and onward, though.


> No idea if that's still the case for GTK3 and onward, though.

It's not. GTK3/4 apps look like GTK apps on every platform and don't even try to fit in.


Quite annoying even on Linux if you use KDE: GTK3 apps stand out like a sore thumb. More than Electron even.


There is a breeze gtk theme available


Yes, but if you use a 'modern' GTK3 app (take a recent Meld), the absence of the titlebar (or decorated one, if you are into mdern GTK) really stands out. You're right that with some (older?) GTK apps breeze-gtk-theme used to work pretty well, not sure what changed.


For what it's worth, I'm using Evolution (which uses GTK3 now) on KDE and it uses the Breeze theme just fine. It also doesn't use header bars.


It is used, but with a modified titlebar bar the styling on it seems to be ignored. GTK3 apps that leave the titlebar alone are fine (Quidlibet for instance).


The author talks about how android doesn’t use GTK. What does Android use? Some kind of Java thing?


Its own toolkit, if I'm not mistaken. Here's the class used to create a button for instance: https://developer.android.com/reference/android/widget/Butto...


Wow the text rendering is atrocious. Is this still the state of GTK and desktop Linux today?


It appears that the author had disabled font antialiasing. Any mainstream Linux distro released in the past 10+ (maybe 20) years would have better font rendering by default - but if you wish, you can disable those defaults by changing a few symlinks in /etc/fonts and revert to 1980s style pixelated rendering. Which is ok, some people prefer the retro look.


IMO it looks worse than X11 core rendering because those fonts are often bitmap fonts made to look good without antialiasing whereas just disabling antialiasing in vector fonts often looks too jaggy. Some fonts have good hinting but the vast majority do not bother.

In Windows i also disable antialiasing since i do not like the blurry look but i also force fonts in web sites with good hinting since most sites look horrible with their preferred fonts.


No, it's just the author's configuration. Looks just like the core X11 font rendering of old, but I guess you could configure the modern font rendering system to look just as terrible by turning of anti-aliasing.


Author is just weirdo.

Here is a "normal" system looks like https://imgur.com/a/hvKNWIs

Everything that isn't a terminal or VSCode on those screenshots is GTK3.

Everything has the same color scheme, icons, fonts. Qt included.


Not sure why your comment has been downvoted. I couldn't agree more with you on your finding and the question follows naturally for someone not familiar with Linux desktops.

Others have meanwhile clarified that anti-aliasing wasn't enabled in the examples, which is easy enough to do and is in all production code. Not sure, whether the author had some retro-look effect in mind or just wanted to visually emphasize the examples (he sure succeeded in both).


Title should be: GTK4 for Graphical User Interfaces with Nim




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: