Starting Qt app under Linux with super user rights: QApplication style is not set!



  • I just discovered this, and can't explain why it is like that:

    Under Linux (Ubuntu 12.04), when I start my Qt application with "./myApp.sh", then everything looks fine (i.e. neat, the default style).
    But when I start with "sudo ./myApp.sh", the style is minimalistic it appears (i.e. it looks ugly).

    Even using "QApplication::setStyle("plastique")" in my application doesn't have any effect (when sudo is used).

    Anyone knows what is going on here?

    Thanks for any insight!



  • I have noticed similar thing.
    I am using Ubuntu 10.04, Qt 4.7.4.

    user@user-desktop:~$./MyApp (Looks fine, comes up with current Desktop theme.)

    user@user-desktop:~$ sudo ./MyApp(My qt application which should have root permissions to run.) comes up with a different look.

    I need Myapp to comes up with user current theme. Dose QT provide any such feature to handle current scenario ?

    Any idea how this can be fixed .

    Please help me with your suggestions.


  • Moderators

    When using sudo the application is normally run as user root, not as the current user.

    That one most likely has themes, fonts, etc. set up and thus your application ends up using the built-in defaults. Fix the setup for root and you should be fine.



  • I'm not familiar with setting up root since I use a Debian based system and root is disabled. We only have sudo.

    Excuse my ignorance, but exactly would you go about setting up those defaults?


  • Moderators

    Debian has a enabled root user by default AFAIK. It is just ubuntu that does not. Sudo is just another way to make yourself root.

    You can do any of the following: Just do "xhost +" to allow anybody access to your display (use xauth instead if you are not alone on your computer!), then do "sudo su -" and you end up in a shell running root.

    Set up X windows (export DISPLAY=:0 should do the trick if it does not work without any magic) and run the system configuration utility of your desktop environment to set up the theming. For gnome/unity that should be gnome-control-center, for kde kcontrol IIRC, but I don't know for XFCE and what else you might be using;).

    Don't forget to set "xhost -" after leaving the root shell again to block others from connecting to your display.

    Note that all these settings are completely independent of what the user is actually using! You can not have root just use the theming of the user that ran sudo. Otherwise that user might be able to sneak code into root's programs (e.g. a theming engine).



  • Older thread but this is exactly my problem. I have a program that I need to start with root permissions. Something I have done to my Linux Mint 13 install makes it so it works great (launched with root by "sudo appName" matches look and feel when launched as normal user).

    However, on Ubuntu 12.04 and 13.04 test machines, I get the generic "Win 95" look when launching as sudo. I have tried dconf-editor (for root) and all the related gsettings set commands (as root) to try and set the theme, etc. So, now root's theme supposedly reports "Ambiance", but the "Win 95 look" continues. Somehow it is not being respected.

    Any help would be appreciated: users are thinking the program is shoddy (well, it may be, but at least it should look better than it does if I can get it to use the theme :-)



  • I should note that many indicate to simply link root/.themes to ~/.themes. But for me I don't have any local themes: only system themes in /usr/share/themes.

    To test I have even done this:

    cp -Rf .config/ .fontconfig/ .gconf/ .gnome2/ /root/

    In order to get root settings to match user. But still no luck (on Ubuntu 12.04 / 13.04)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.