QT6 on Ubuntu 22.04 strange widget behavior
-
We recently upgraded to Ubutnu22.04, with QT 6.5.1 installed using the online installer.
When porting some of our older (QT <= 5) apps, I noticed a strange issue with buttons, and progress bars, (so far) .
In the designer, when I add a new button or progress bar, this is how they look:
When I run the app, this is what I get:
Here's the real kicker, this is what happens when I resize/move the window:
I tried looking online if anybody has had this issue, but couldn't really find anything. Any help is appreciated.
-
I found something, it seems to have solved the issue, but I don't understand why.
After posting the question I had a feeling that it might be related to environment variables, somehow. So in
main
I wrote a simple routine which outputs all environment variables to a file, each environment variable and it's value on a different line.I then edited the file such that each environment variable was prefixed with
export
, and at the end of the file I ran the program.Then running the file as a script using
env -i ./file
to see which environment variable was the culprit I found two.GNOME_DESKTOP_SESSION_ID=this-is-deprecated
XDG_CURRENT_DESKTOP=ubuntu:GNOME
For some reason these two environment variables mess with QT's renderer(???).
Now, there's one last thing which I need help with.
Iunset
those environment variables in.bashrc
which, when I run the program from a terminal, the program runs correctly, but when I double click to the the program, the issue persists. Is there a way I can globallyunset
an environment variable from a user?Edit/update: I tried adding
unset GNOME_DESKTOP_SESSION_ID
unset XDG_CURRENT_DESKTOP
to.profile
which did "fix" the issue, the program ran correctly when double-clicking. However, it also completely changed how the desktop looks. Which is also a problem. -
I don't know if "self-bumping" is against the rules, but I really need help with this
-
I have an update, no solution yet, but an update.
A user on Reddit suggested to that I run the app with
-style fusion
and-platform xcb
, there wasn't much change there. Then he suggested I useexport QT_LOGGING_RULES=*.debug=true
before running the app, I ran the app once withXDG_CURRENT_DESKTOP
set, and once withunset XDG_CURRENT_DESKTOP
.Comparing the two files, I found the following
.qpa.theme: Attempting to create platform theme "gtk3" via QPlatformThemeFactory::createqt.core.library: "/home/vbboard1/Qt/6.5.1/gcc_64/plugins/platformthemes/libqgtk3.so" loaded libraryqt.qpa.theme.dbus: "" "/org/freedesktop/portal/desktop" "org.freedesktop.portal.Settings" "SettingChanged"qt.qpa.gtk: Color map populated from defaults.qt.qpa.gtk: GTK theme initialized: "Yaru" Qt::ColorScheme::Lightqt.qpa.theme: Successfully created platform theme "gtk3"
As I understand, "Yaru" is a type of theme used by KDE. Why is it being loaded here with Ubuntu on gnome. Is there any way I can disable it?
-
@Josef-Lintz If you want to set them for your app only, you can do it in main()
with
qunsetenv("GNOME_DESKTOP_SESSION_ID");
qunsetenv( "XDG_CURRENT_DESKTOP" );
before QApplication app call. These settings will affect your app only. -
@Josef-Lintz https://wiki.archlinux.org/title/Xdg-utils
XDG_CURRENT_DESKTOP=ubuntu:GNOME because you installed gnome.
mine is LXQt. You may need to make your code working for different settings. -
@JoeCFD Thanks for the suggestion. I actually came up with a similar way to run the programs. I simply prefixed the program name with
.
and created a bash file with the same name as the program and before launching the program I do:
unset GNOME_DESKTOP_SESSION_ID
unset XDG_CURRENT_DESKTOP
But this doesn't solve the underlying issue. Why is it that on my system (A fresh install, bare in mind) with QT installed using the online installer, I get 3 different conflicting "styles(?)", when in designer, when running, or when modifying window/focus.
Also, your approach and mine still has the same issue(s), I have to do this for a lot of programs we use, so it's not very feasible.
And, it's only recently I noticed this issue, when I do
unset GNOME_DESKTOP_SESSION_ID
unset XDG_CURRENT_DESKTOP
Some of the widgets still appear wrong, I asked a question about this a while back (This was for Ubuntu 16.04). It ended up being an environment variable not being set correctly.So, even if doing
unset GNOME_DESKTOP_SESSION_ID
unset XDG_CURRENT_DESKTOP
seems to work, it doesn't fix the issue fully -
@Josef-Lintz Can you check this output?
echo $XDG_SESSION_TYPEI do not think Qt should have any issue with the following setting.
XDG_CURRENT_DESKTOP=ubuntu:GNOME -
@Josef-Lintz Can you check this output?
echo $XDG_SESSION_TYPEecho $XDG_SESSION_TYPE
returns "x11"I do not think Qt should have any issue with the following setting.
XDG_CURRENT_DESKTOP=ubuntu:GNOMEI think I figured out something. If I set
XDG_CURRENT_DESKTOP
to anyhing, not justunset
it, I get the same result as the 3rd image. So, it's possible thatXDG_CURRENT_DESKTOP
is set correctly, but the preview/designer is wrong?
Also, still doesn't explain why the style changes when I move/resize the window -
Hi @Josef-Lintz,
with Qt 6.5, a new version of Qt's GTK3 theme has been shipped, which generally improves GTK look and feel. I wrote it, so now you know whom to blame ;-)Looking at your observations:
-
When the widget containing the progress bar and the push button is moved or resized, it implicitly gets focus. I guess that's the reason why the colors change. They change from the
Inactive
to theNormal
color group. That said, the new GTK3 styling probably makes a change visible, that had been invisible before.
You can check that by obtaining the widgets' palette e.g. withconst QPalette &palette = ui->pushButton->palette();
and inspecting their colors.
This, as an example returns the normal button color.
qDebug() << palette.color(QPalette::Normal, QPalette::Button).name();
(changeNormal
toInactive
to retrieve the initial colors) -
Furthermore, this patch landed in 6.5.2 yesterday. It is (under more) related to the Yaru style. In essence, the GTK button foreground was used for the WindowText, before it would fall back to other (more suitable) colors. That has worked nicely for some GTK themes, but was unfortunate for others. It affects only text color, but since you are working with Yaru, I found it worth mentioning.
Cheers
AxelPS: Thanks to @Matthias-Rauter for prompting.
-
-
@Axel-Spoerl Thank you very much for the explanation.
So, it seems like a small bug(?) in how the styles are set-up. Ok, but it still begs the question as to why "normal" is different in the designer vs runtime? And is it something I can fix "locally" or do I need to wait for an update?And one more thing, (kind of a silly question) I can't seem to update to QT 6.5.2, I tried the unified installer, and I only got listings up QT 6.5.1?
According to this, QT6.5.2 has not yet been "Realized", my bad -
@Josef-Lintz
Hi Josef,
I understand the add-on-question. The widget designer provides an abstraction level to design widget based applications. It can't anticipate, where the application actually runs. Could be Linux/KDE, Linux/Gnome, Windows, macOS, dark mode, light mode. It doesn't have the ambition to completely emulate the look and feel of the local machine.
Cheers
Axel -
@Axel-Spoerl I truly appreciate that you're explaining what the issue is. But how can I fix it, is it even something "fixable" on my end, or do I need to wait for the next QT version?
-
@Josef-Lintz
What are you expecting to be "fixed"? @Axel-Spoerl explained that Designer preview will not be identical to runtime. If it's that things look a bit different that is not going to change. -
@JonB Well, if the designer is meant to preview how the program should look like, and it looks completely different from the preview during runtime, then I think the designer isn't working correctly (Assuming you don't do anything weird to the layout during runtime). And there should at least be a way to configure the designer, to make it preview the actual design more correctly.
(Bit of nit-pick I don't think calling it "slightly different" is doing this justice. Most of the widgets look completely different as to how they look in "design-time")
If the styling is different between design-time and runtime, maybe I can live with it. But the fact that the styles completely change when the widgets lose focus, is somewhat problematic, I guess that's the main issue here
I apologize if my earlier remarks came off as rude, that wasn't my intention.
-
This post is deleted!
-
@Josef-Lintz
I only meant if it looks "somewhat" different. If it's, say, a completely wrong color that would indeed be bad. @Axel-Spoerl knows much more than I do about the specifics. -
@Josef-Lintz said in QT6 on Ubuntu 22.04 strange widget behavior:
if the designer is meant to preview how the program should look like
I can understand the point. However, it would make the widget designer way more complex. Where should the line be drawn? Should it emulate macOS look'n'feel on Linux? Gnome YaruDark on Windows in light mode?
But that's getting us off topic: If there's anything we can improve on the GTK theming shipped with Qt 6.5, I'd be grateful for any input. And, as @JonB said, if the widget designer shows something completely odd, just point it out.
-
I can understand the point. However, it would make the widget designer way more complex. Where should the line be drawn? Should it emulate macOS look'n'feel on Linux? Gnome YaruDark on Windows in light mode?
I mean, why not though? Isn't the point of the designer to preview how your program is going to look like? Having a designer which produces different output while in "design-mode" vs runtime, kinda defeats the point of having a designer?
QT apps (as far as I saw) already support theming, even "cross-platrform" themes, I can have a "Windows-looking" QT app run on Ubuntu. So I don't see the problem with said "line". I guess by default the designer should look like the system-theme, unless specified otherwise by the user.
If it's an issue of complexity, since QT Widgets is less supported than QT Quick, I can understand.But that's getting us off topic: If there's anything we can improve on the GTK theming shipped with Qt 6.5, I'd be grateful for any input. And, as @JonB said, if the widget designer shows something completely odd, just point it out.
This is interesting, am I the first person to encounter this "issue"? Has nobody on Ubuntu 22.04 encountered this problem before? When installing Ubuntu I chose the "Minimal installation" option, could it be that it skipped something that a "Full installation" uses?