11

My code is throwing the warning (not sure if this is actually a warning)

QApplication: invalid style override passed, ignoring it.

but nothing else. It does not tell me which part of the code is raising it.

How can I know which part of my code is triggering this warning?

Gabriel
  • 40,504
  • 73
  • 230
  • 404
  • 1
    Sorry, mind reading machine is broken again. Can you post your code? :) – Sergio Monteleone Apr 12 '18 at 17:51
  • 1
    That's the whole point, I don't know where in my code this warning happens since no clue is given by the warning itself. The code is thousands of lines long. – Gabriel Apr 12 '18 at 17:56
  • Did you enable fusion style? Can you show the code before the initialization of QApplication? – Sergio Monteleone Apr 12 '18 at 17:58
  • No idea what *fusion style* is and I do not initialize QApplication anywhere in my code that I am aware of (I don't even know what that means/does) I'll use some `print` statements to try and pin down the issue. – Gabriel Apr 12 '18 at 18:01
  • Don't you have anywhere in your code a line like "app = QApplication(sys.argv)" ?? – Sergio Monteleone Apr 12 '18 at 18:07
  • I don't even have the word *QApplication* in my code. – Gabriel Apr 12 '18 at 18:24
  • Well if you don't use Qt at all in your code then either you use some libraries that use Qt, or you launch from your code an application based on Qt, or the message you see in console is not generated by your application at all... Can't be more specific without knowing which OS you are using. – Sergio Monteleone Apr 12 '18 at 18:29
  • Possible duplicate of [PyQt5 does now show icons?](https://stackoverflow.com/questions/44080247/pyqt5-does-now-show-icons) – Mohammad Kanan Apr 13 '18 at 12:20

5 Answers5

8

The cause for this message is that the environment variable QT_STYLE_OVERRIDE is set on your system to a value not supported by your Qt installation. You can check this with

    sh-prompt> set | grep QT

To fix this warning, you can either change the variable in /etc/profile or $HOME/.bashrc, or -if only one program is affected- start the program with

    QT_STYLE_OVERRIDE="" program

Unsetting the varible with qputenv in your program code (as Harvey suggested) will have the side effect that style preferences are ignored by your application even on systems that support it.

cdalitz
  • 1,019
  • 1
  • 6
  • 7
4

This problem comes from qt 5.9.2 and pyqt 5.9.2. This problem is known to Anaconda team and they are ignoring it because it primarily comes from qt.

I got this error for anaconda-navigator (Anaconda3-5.2.0-Linux-x86_64) and this caused my Spyder (v3.2.8) IDE for Python 3.6 getting invisible. Downgrading qt and pyqt solved the problem.

To downgrade, type in console:

conda install pyqt=5.6

Note: In case, your conda is not updated, you need to update conda before running the above command. To update conda run:

conda update -n base conda

Hope this will solve your problem too.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Narnia_Optimus
  • 326
  • 1
  • 16
1

How can I know which part of my code is triggering this warning?

Start with the parts of your code that invoke a GUI. Given that the OP appears to be a scientist, I'll take a wild guess that matplotlib is involved. I can reproduce the message with

import matplotlib.pyplot as plt
plt.plot([1, 2])

using the following package versions (from conda list):

matplotlib                2.2.2            py36h0e671d2_1    defaults
pyqt                      5.9.2            py36h751905a_0    defaults
qt                        5.9.4                h4e5bff0_0    defaults
drammock
  • 2,373
  • 29
  • 40
  • I have those exact versions except that `matplotlib` and `pyqt` are the `27` versions (since I am working with Python 2.7) – Gabriel May 04 '18 at 01:14
  • @Gabriel can you reproduce the message with the 2-line example I gave? If so, please consider marking this question as solved. – drammock May 04 '18 at 16:07
  • Yes, sorry I forgot to accept your answer. Thank you! – Gabriel May 04 '18 at 16:25
  • This is not a Matplotlib issue (see https://github.com/matplotlib/matplotlib/issues/11775). It might be an Anaconda issue. – Alejandro Jul 26 '18 at 13:12
  • @Alejandro It's definitely not an Anaconda issue. I got the warning and I do not even have anaconda installed. It's a QT issue it seems. ;) – spirit Nov 11 '18 at 21:33
1

[EDIT]: I just found a better solution for my own C++ code. It is still only a "workaround," but the warning is gone. Add one line at the very top of the main() function, like this:

int main(int argc, char *argv[])
{
    qputenv("QT_STYLE_OVERRIDE",0);
    ...

This will unset the environment variable causing the warning.

[OLD ANSWER]:

Error message:
 QApplication: invalid style override passed, ignoring it.

To remove this error message:
 In Qt Creator (ver 4.4.1)
  Select "Projects" (wrench icon on left edge)
   Under "Build & Run" (left pane)
    Select "Run"
     Under "Run Settings" (right pane)
      Under "Run Environment"
       Select "Details" (drop down list)
        Scroll down to "QT_STYLE_OVERRIDE"
         Click it to highlight it
         Then click "Unset" button (right side)
       Click "Details" to close the list

Now when you run the application you shouldn't see this error message.
Harvey
  • 2,062
  • 2
  • 21
  • 38
  • I am not using Qt Creator. – Gabriel Aug 13 '18 at 17:48
  • I just today found a much better workaround. Qt Creator not involved now. Edited my answer. – Harvey Aug 14 '18 at 23:38
  • I don't really understand this answer. Is it C++ code? – Gabriel Aug 15 '18 at 14:52
  • @Gabriel yes it is C++ code. (Ignore the "OLD ANSWER.") I am using Qt, but I expect this may work for anyone with any Qt code somewhere in their project. If you are getting this error, then you quite certainly have Qt code somewhere since it is a complaint from "QApplication: ..." The main() function is the standard starting point for any C++ application. Are you using C++? – Harvey Aug 16 '18 at 00:24
  • @Gabriel I see you have the Python tag. Hopefully you can find an equivalent statement to put at the very beginning of your Python code, to set this environment variable QT_STYLE_OVERRIDE to an empty string "" (or NULL, as I did.) – Harvey Aug 16 '18 at 00:30
  • The OLD ANSWER did the trick for me! – Zac Jul 27 '22 at 09:58
0

On Ubuntu 18.04, I installed anaconda.

$ anaconda-navigator

QApplication: invalid style override passed, ignoring it.

When running spyder from anaconda-navigator:

/home/username/.anaconda/navigator/scripts/spyder.sh: line 3: 31873 Segmentation fault      (core dumped) spyder >
/home/username/.anaconda/navigator/scripts/spyder-out-1.txt 2>
/home/username/.anaconda/navigator/scripts/spyder-err-1.txt

When running spyder from the command line:

/home/username/.anaconda/navigator/scripts/spyder.sh: line 3: 31873 Segmentation fault      (core dumped) spyder > 
/home/username/.anaconda/navigator/scripts/spyder-out-1.txt 2> 
/home/username/.anaconda/navigator/scripts/spyder-err-1.txt

This fixed my problem:

$ conda install pyqt=5.6

Many thanks to Narnia_Optimus

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
rwg
  • 21
  • 3