My program has the main GUI thread to handle the user interface.
Another thread is started to handle the hard work (loops, calculations, etc) without freezing the main GUI.
From my "calculations thread" I am using another module draw_plots
which only draws and saves many kinds of plots.
import draw_plots as plots
class calculatorThread(QtCore.QThread):
signal1 = QtCore.pyqtSignal(int, int)
signal2 = QtCore.pyqtSignal(int,int)
signal3 = QtCore.pyqtSignal(int)
def __init__(self,input_file_txt, parameter_file_txt):
QtCore.QThread.__init__(self)
#and etc etc
At some point of this thread I am calling:
plots.stacked_barplot(*arguments)
Everything works fine, however, I get a message on the screen many many times:
QPixmap: It is not safe to use pixmaps outside the GUI thread
Would like to know what am I doing wrong and how to avoid this message.
Well, you issue the plot command from the calculator thread, which in turn uses a QPixmap to draw the plot - all from inside your calculator thread.
Ideally, you shouldn't draw from the calculator thread, but e.g. emit a signal that you're ready for plotting - and do the plot in the main thread. Maybe along the following lines:
class calculatorThread(QtCore.QThread):
plot_emit = QtCore.pyqtSignal()
def run(self):
self.plot_args = your_calculation()
self.plot_ready.emit()
Outside, connect the plot_ready
signal to your plot command:
calculator.plot_emit.connect(lambda x:
plots.stacked_barplot(*calculator.plot_args))