How to correctly set QT_QPA_PLATFORMTHEME according to the WM I'm using? My script doesn't seem to work

I created this script at ~/.config/i3/scripts/qt6ct.sh to set QT_QPA_PLATFORMTHEME depending on whether I’m using Plasma or I3wm:


<span style="color:#323232;">#!/bin/bash
</span><span style="color:#323232;">CURRENT_DESKTOP=$(echo "$XDG_CURRENT_DESKTOP")
</span><span style="color:#323232;">
</span><span style="color:#323232;">if [ "$CURRENT_DESKTOP" = "i3" ]; then
</span><span style="color:#323232;">    export QT_QPA_PLATFORMTHEME="qt5ct"
</span><span style="color:#323232;">
</span><span style="color:#323232;">elif [ "$CURRENT_DESKTOP" = "KDE" ]; then
</span><span style="color:#323232;">    # Si estás usando Plasma (KDE), comentar la línea que exporta la variable
</span><span style="color:#323232;">    unset QT_QPA_PLATFORMTHEME
</span><span style="color:#323232;">else
</span><span style="color:#323232;">    echo "Gestor de ventanas no es i3 ni kwin: $CURRENT_DESKTOP"
</span><span style="color:#323232;">fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">echo $CURRENT_DESKTOP
</span><span style="color:#323232;">echo $QT_QPA_PLATFORMTHEME
</span>

I created an autostart program and added this to my i3 config file


<span style="color:#323232;">exec ~/.config/i3/scripts/qt6ct.sh
</span><span style="color:#323232;">exec source ~/.config/i3/scripts/qt6ct.sh
</span>

I don’t know what’s wrong with it, but if I run it on a terminal, I get this (screenshot):


<span style="color:#323232;">➤ ~/.config/i3/scripts/qt6ct.sh 
</span><span style="color:#323232;">i3
</span><span style="color:#323232;">qt5ct
</span><span style="color:#323232;">➤ echo "$QT_QPA_PLATFORMTHEME"
</span><span style="color:#323232;">                    
</span><span style="color:#323232;">➤
</span>

So this script doesn’t really export anything at all.

I have searched on every file that I thought could be exporting it as a null value (~/.bashrc, ~/.profile, ~/.bash_profile, ~/.xinitrc, ~/.Xresources, /etc/environment, /root/.profile, /root/.bashrc), but everything looks fine (no QT_QPA_PLATFORMTHEME anywhere, or is commented).


Solution

The only thing we’ll need in.xprofile is sourcing the script:


<span style="color:#323232;">#!/bin/bash
</span><span style="color:#323232;">CURRENT_DESKTOP=$(echo "$XDG_CURRENT_DESKTOP")
</span><span style="color:#323232;">
</span><span style="color:#323232;">if [[ "$CURRENT_DESKTOP" = "i3" ]]; then
</span><span style="color:#323232;">    export QT_QPA_PLATFORMTHEME="qt5ct"
</span><span style="color:#323232;">    export QT_SCREEN_SCALE_FACTORS=1.5 # 1.5
</span><span style="color:#323232;">    export QT_AUTO_SCREEN_SCALE_FACTOR=0
</span><span style="color:#323232;">elif [[ "$CURRENT_DESKTOP" = "KDE" ]]; then
</span><span style="color:#323232;">    unset QT_QPA_PLATFORMTHEME
</span><span style="color:#323232;">    export QT_AUTO_SCREEN_SCALE_FACTOR=1
</span><span style="color:#323232;">
</span><span style="color:#323232;">else
</span><span style="color:#323232;">    echo "Gestor de ventanas no es i3 ni kwin: $CURRENT_DESKTOP"
</span><span style="color:#323232;">fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">echo $CURRENT_DESKTOP
</span><span style="color:#323232;">echo $QT_QPA_PLATFORMTHEME
</span><span style="color:#323232;">echo $QT_SCREEN_SCALE_FACTORS
</span><span style="color:#323232;">echo $QT_AUTO_SCREEN_SCALE_FACTOR 
</span>
sin_free_for_00_days,

BASH is so annoying. Try fixing your spaces. On my terminal I get this:


<span style="color:#323232;"> [ "$CURRENT_DESKTOP" = "i3" ] && echo True
</span><span style="color:#323232;">
</span><span style="color:#323232;"> [ "$CURRENT_DESKTOP"="i3" ] && echo True
</span><span style="color:#323232;"> True
</span>
Moshpirit, (edited )
@Moshpirit@lemmy.world avatar

LOL you’re right! Yet, I am still getting no better result when changing it:


<span style="color:#323232;">➤ ~/.config/i3/scripts/qt6ct.sh 
</span><span style="color:#323232;">i3
</span><span style="color:#323232;">qt5ct
</span><span style="color:#323232;">➤ echo "$QT_QPA_PLATFORMTHEME"
</span><span style="color:#323232;">
</span><span style="color:#323232;">➤ ~/.config/i3/scripts/qt6ct.sh 
</span><span style="color:#323232;">i3
</span><span style="color:#323232;">qt5ct
</span><span style="color:#323232;">➤ source ~/.config/i3/scripts/qt6ct.sh 
</span><span style="color:#323232;">i3
</span><span style="color:#323232;">qt5ct
</span><span style="color:#323232;">➤ echo "$QT_QPA_PLATFORMTHEME"
</span><span style="color:#323232;">qt5ct
</span>

Ok, here are very interesting things:

  1. I added source ~/.config/i3/scripts/qt6ct.sh at .profile, and logout. When I logged in, nothing has changed. I don’t know why, since when I manually run it, it apparently changes the value of QT_QPA_PLATFORMTHEME.
  2. After doing all of that, Qt apps doesn’t seem affected at all, when I open the qt5ct application from Rofi, it keeps showing me the same warning (something like: The QT_QPA_PLATFORMTHEME environment variable has not been set (required values: qt5ct or qt6ct)).
  3. AFTER I do all of this, if I run qt5ct or run rofi --show -drun and then select the qt5ct app, then it works just fine. The same happens with dolphin: if I run it from rofi, then it looks awful, but if I run it from the terminal, it looks great. BUT if I close the terminal and open it again, everything goes back to normal (meaning: awful).

After including source ~/.config/i3/scripts/qt6ct.sh to /etc/environment and rebooting to see if anything changed: nope. No changes, the problem persists.

sin_free_for_00_days,

OK, I have neither qt apps, nor other desktops, so I’m kind of shooting in the dark. I seem to remember reading that .profile is sometimes not looked at and it’s better to put in .bash_profile or even paste it into your .bashrc and see you still have the issue.

Moshpirit,
@Moshpirit@lemmy.world avatar

Ok, something happened: adding it to .bash_profile did change QT_QPA_PLATFORMTHEME on i3 (whoohooo \o/), BUT it also did on plasma (ouch 😢), so the script for some reason is not returning what is supposed to.

sin_free_for_00_days,

Paste what you’ve got so far and I’ll look at it some more.

Moshpirit, (edited )
@Moshpirit@lemmy.world avatar

I think I figured it out, I created a .xprofile file and moved all the env stuff there:


<span style="color:#323232;">➤ cat .xprofile
</span><span style="color:#62a35c;">source </span><span style="color:#323232;">~/.config/i3/scripts/qt6ct.sh
</span><span style="font-weight:bold;color:#a71d5d;">export </span><span style="color:#323232;">QT_SCREEN_SCALE_FACTORS</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">1.45 </span><span style="font-style:italic;color:#969896;"># 1.5
</span><span style="font-weight:bold;color:#a71d5d;">export </span><span style="color:#323232;">QT_AUTO_SCREEN_SCALE_FACTOR</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">0 </span><span style="font-style:italic;color:#969896;"># 0
</span>

Now dolphin uses breeze themes, thunar uses its gtk version and also found out about how to fix the zoom issue (it was supposed to be another different battle but seems like they have more in common than what I thought!)

Thank you so much for helping me all the way here!! :)

Correction: I didn’t entirely fix it!

There’s a couple of stuff to be fixed: screenshot

  • calendar widget looks huge
  • dolphin space/zoom status are not blue, but black.
  • probably other stuff to be discovered

Which means that in Plasma QT_QPA_PLATFORMTHEME is still read as qt5ct :(

Correction 2: I FIXED IT!!

remove everything from .xprofile except sourcing the script:


<span style="color:#323232;">#!/bin/bash
</span><span style="color:#323232;">CURRENT_DESKTOP=$(echo "$XDG_CURRENT_DESKTOP")
</span><span style="color:#323232;">
</span><span style="color:#323232;">if [[ "$CURRENT_DESKTOP" = "i3" ]]; then
</span><span style="color:#323232;">    export QT_QPA_PLATFORMTHEME="qt5ct"
</span><span style="color:#323232;">    export QT_SCREEN_SCALE_FACTORS=1.5 # 1.5
</span><span style="color:#323232;">    export QT_AUTO_SCREEN_SCALE_FACTOR=0
</span><span style="color:#323232;">elif [[ "$CURRENT_DESKTOP" = "KDE" ]]; then
</span><span style="color:#323232;">    unset QT_QPA_PLATFORMTHEME
</span><span style="color:#323232;">    export QT_AUTO_SCREEN_SCALE_FACTOR=1
</span><span style="color:#323232;">
</span><span style="color:#323232;">else
</span><span style="color:#323232;">    echo "Gestor de ventanas no es i3 ni kwin: $CURRENT_DESKTOP"
</span><span style="color:#323232;">fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">echo $CURRENT_DESKTOP
</span><span style="color:#323232;">echo $QT_QPA_PLATFORMTHEME
</span><span style="color:#323232;">echo $QT_AUTO_SCREEN_SCALE_FACTOR 
</span>
sin_free_for_00_days,

Haha, that’s great! That post was like a rollercoaster.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • techsupport@lemmy.world
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • anitta
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • provamag3
  • tester
  • Leos
  • megavids
  • JUstTest
  • All magazines