4

I'm trying to use Qt to make a very simple window.

My goal is to obtain something that looks like a native OS window (with the least effort), nothing more, but if possible nothing less.

In order to make it easier, I'm using Qt python bindings, and I tried different combinations since my first one somehow failed. Choices I have to make are:

  • PyQt or PySide
    • I'd prefer the second, since it's the one official support (and they're pretty equivalent)
  • Qt5 or Qt6
    • I'd prefer the second, since it's the latest stable

Now, as said before I tried different combinations, but the first choice seems irrelevant, while the second matters:

  • Qt5 window looks the same on XOrg and Wayland
  • Qt6 window not, no matter which python package I use (PyQt or PySide)

In particular Qt6 on Wayland overrides default OS style, including the pointer (i.e. the pointer changes while hovering the Qt6 window), and it doesn't happen on XOrg, neither it happens for Qt5 (where on Wayland and on XOrg has the same appearance).

Here a couple of screenshots for a simple example:

  • Qt6 (PySide6) on Wayland

qt6-wayland

  • Qt6 (PySide6) on XOrg

It is understood that the two windows are generated by the very same script...

qt6-xorg

Annibale
  • 241
  • 3
  • 6
  • How do you define which graphical system to use (choose X11 instead of Wayland)? – Naourass Derouichi Mar 18 '23 at 07:36
  • The graphical system is a service you launch (or someone for you). You might have only one installed, or no graphical way to switch, according to your OS (in this case your Linux distro). But you can always boot into a tty and manually launch. In this case, Ubuntu is transitioning between Xorg and Wayland, so from the login screen there is a wheel icon, and you can select which one to launch while logged out, and it will be launched by the login manager. – Annibale Mar 19 '23 at 08:04
  • Thanks for the info @Annibale. Inside PySide6 project, how to make Qt6 use X Server instead of Wayland and vice versa? – Naourass Derouichi Mar 19 '23 at 08:50
  • The one tested above is the same code: just a plain window with a few labels, buttons, and text boxes. Once run, it is just using the available graphic server on its own (i.e. if you are running on Xorg it will connect to it, same for Wayland). – Annibale Mar 19 '23 at 17:15

1 Answers1

1

First of all, while aiming for the same "result" (display and interaction for the end user), Xorg and Wayland are very different: the first is a server, the second is a protocol.

While having been in active development for almost a decade, the introduction of Wayland to mainstream usage is pretty recent (as opposed to X, which has been used for more than 30 years), meaning that it still requires time to achieve a level of "transparent comparison".

"Themeing" is not just a matter of porting, since the appearance of an UI depends on very different aspects between those two systems. For instance, on X the client uses system mouse cursor (unless overridden), while on Wayland the cursor has to be set by the client (usually, the toolkit, Qt in this case).

Qt, being such a huge effort in cross-compatibility support, relies on a plethora of system hooks (platform plugins) that are not easy to deal with, especially in the Linux environment for which there are infinite possible configurations. Different appearance between those two is expected (at least, right now) and might be due to a multitude of aspects, many of which depend on the the window environment, installed themes and customization by the distro. It might help knowing what Linux version you're using, if you're using custom repositories, and the installed Qt and wayland versions.

With all that in mind, and especially on Linux, there's no such thing as "native window". There is an appearance that is compliant with the current window environment, but there are lots of aspects that may interfere with that, including the OS itself, and sometimes Qt can do very little with it, especially if the OS doesn't care a lot about other toolkits or uses specific customization (see Ubuntu/Gtk and the various incarnations of that distro).

Due to the deep changes some core aspects of Qt6 underwent (including Wayland support), it will probably require some more time to reach the same level of compatibility Qt5 has right now, and that also depends on how the related FOSS communities will react in the meantime. For the time being, unless you really need aspects that are only available for Qt6, if you're still beginning to study and develop with Qt, I'd suggest to stick with Qt5 for a while: it's still widely used and supported for general usage, meaning that you'll find help and resources more easily, while with Qt6 there's still room for doubts when a problem is actually caused by Qt, it's specific to a certain version or some OS/platform aspects (like it probably is in your case).
Whenever you'll want to switch to Qt6, the transition will be almost transparent and generally easier than it was between Qt4 and Qt5, with only few important changes that will require more attention (for instance, QAction has been moved to the QtGui module).


Finally, a couple of notes on your considerations about Qt and its bindings.

Qt6 is the latest stable

This is a partially wrong assumption: "stable" doesn't mean "the latest" nor "the best". The fact that a stable major version was released more recently doesn't make the latest stable release of the previous major version is "less" stable.
Qt5 has been developed and widely used for almost a decade (with many core features developed and "stabilized" years before with Qt4), which means that it is very stable, especially if compared to Qt6, that was released just one year ago, and is still going through deep development: some features have been [re]introduced and radically changed just a few months ago and it still receives dozens of bug reports a day.

It is true, though, that Qt made a questionable move a year ago deciding to limit future bugfix releases of the Qt5 branch only for commercial licensees, which raised some serious concerns since Qt6 was yet not as stable nor full-featured as Qt5 (and, while important progress has been made, still isn't). A proposal for a free fork exists, but nothing has happened yet.

That said, Qt5.15 is stable, and if you ever face a problem that was fixed in the commercial releases only it's very likely that you can work around it pretty easily anyway.

About the PyQt/PySide differences, while it's true that PySide is the "official" supported python binding, that's not the only aspect you should consider when comparing them. Besides the aspect of the license, there are some differences in how those two bindings work and their support/features: for instance, PyQt adds support for some more pythonic aspects, and notably has the uic.loadUi feature that QUiLoader cannot provide in any way.

musicamante
  • 41,230
  • 6
  • 33
  • 58
  • 1
    Thanks for your detailed answer, it adds context to my question, but it doesn't answer it: I've been sloppy over details, like XOrg and Wayland, nevertheless it was descriptive enough you could figure out what I was interested in. I know that "system theme" it's really a relative concept in Linux DE, nevertheless Qt5 or Xorg is doing well in using Gtk style (of course I'm on GNOME...). In particular, I'd prefer it'd follow Ubuntu theming as well, but alternative themes are patch themselves, and not a Gtk feature, so I don't expect it. – Annibale Jan 07 '22 at 12:20
  • Furthermore: in the last part of your answer, you assumed things I didn't put in my question. "Last stable" means the last release among "stable" ones. I prefer to use last stable in general, because they usually supersede the previous ones and get more dev effort. This is a personal choice, and I haven't said anything on Qt5 support. Then on the "official" PySide: in general PyQt and PySide are pretty equivalent, and I asked a different question, no purpose to make a thorough comparison. I chose one, and it worked for me, that's everything I need. – Annibale Jan 07 '22 at 12:26
  • @Annibale I updated the question in the meantime, I don't know if you read the changed parts: the updated parts are partially related to those aspects: Qt6 introduced major core changes (many of which related to platform plugins and wayland) which are still under active development and changes. If you aim for better integration, right now I'd suggest you to stick with Qt5 for a little more. (I only added the PyQt/PySide paragraph for completeness) – musicamante Jan 07 '22 at 12:38
  • I agree that Qt6 looks rather unstable (Wayland related), nevertheless it's even easier to get docs https://doc.qt.io/qtforpython/ and it can only improve in the future. After my experience, I can tell Qt5 might be an easier choice for the time being (where Linux is involved, as in my case), nevertheless I'd like Qt6 to be as good as asap, since authors mostly give up on 5. – Annibale Jan 07 '22 at 15:06
  • @Annibale it's not just just about Wayland, as there are other problems too (for instance, the newly reintroduced QtMultimedia module, which has been *finally* reworked, but now obviously needs some time to reach stabilization). As per the documentation, it's usually better to rely on the official C++ docs in any case (and eventually check the python related pages in case of doubts) as it better helps understanding how functions actually work on the C++ side (studying the sources is also really useful). I'd like to switch to Qt6 too sooner or later, but right now there are more cons than pros. – musicamante Jan 07 '22 at 16:24