Set Qt theme and font without qt5ct

  • I use the i3 window manager and the qutebrowser web browser. I'd like to configure my preferred font face and size for Qt5 without using any graphical tools such as qt5ct. In particular, I'd like to use some plain text configuration file so that it can be added to my dotfiles git repository. qt5ct's configuration file is not really meant to be read by humans, so I don't like it. When I used GTK I could edit the ~/.config/gtk-3.0/settings.ini file and add a few lines:

    gtk-icon-theme-name = Adwaita 
    gtk-theme-name = Adwaita 
    gtk-font-name = DejaVu Sans 11

    Can I do something similar with the Qt5 toolkit? Thanks.

  • I found out I can create a file called stylesheet.qss with the following content:

    * { font-family "Noto Sans"; font-size: 16pt }

    Then I can launch qutebrowser as follows:

    qutebrowser --qt-arg stylesheet /path/to/stylesheet.qss

    This solution seems to be specific to qutebrowser only. How can apply my custom stylesheet to all Qt applications?

  • Lifetime Qt Champion

    I think that has to be supported by your distro - as far as i know the various ways Qt allows it is pr App. Like qt conf and the parameter you used.

    If qt5ct works, could you use that to find out where it put the files if that tool can
    make it work system-wide ?

    You are on ubuntu ?

  • I'm on Gentoo.

  • Lifetime Qt Champion

    @fturco said in Set Qt theme and font without qt5ct:


    Ok. i dont know that distro but if the qt5ct can do it on that distro , it must mean there is a way to set it somehow.
    You could use strace to see if you can find out how its doing it.

  • Unfortunately I don't have any C++/Qt programming skills, so I'm not sure I can understand qt5ct's source code. Learning C++ and Qt is on my todo list anyway, and one of the first real projects could be this one.

    Anyway I found another possible workaround:

    • Configure my favorite fonts in ~/.config/gtk-3.0/settings.ini
    • Add QT_QPA_PLATFORMTHEME="gtk3" to /etc/env.d/99local
    • Run env-update
    • Log out and then log in again

    I guess the dev-qt/qtwidgets needs to be built with the gtk USE flag, but I have not tested it without. Probably the gtk USE flag is needed in order to build the /usr/lib64/qt5/plugins/platformthemes/ file.

  • Lifetime Qt Champion

    I did mean to just use strace on qt5ct and see if you could see if it would store any interesting files
    in some locations.

    Anyway, you solution seems fine also.

Log in to reply