Sometimes we need to add some pictures to the window, below to a method implemented by Qlable.
It is important to note that when you enable multi-threading, the Setpixmap of a method call causes QT to report a thread-safe error.
So, let this drawing work as far as possible inside the QT main thread, can be outside through the way to pass the signal, to avoid this trap. In addition, you can also qimage to add pictures.
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #@Date: 2016-06-02 23:55:324 #@Author: Nevermoreluo ([email protected])5 6 " "7 function:8 add a picture to a label label9 How to use:Ten call Piclabel (imgfile) to get a picture label One A Loading pictures with Qtgui.qpixmap (imgfile) - put the picture in the label label with QtGui.QLabel.setPixmap () - " " the - ImportSYS - fromPysideImportQtgui - +Imgfile ='images/screenshot.jpg' - + A classPiclabel (Qtgui.qlabel): at - def __init__(Self, imgfile, parent=None): -Super (Piclabel, self).__init__(parent) -PIX =Qtgui.qpixmap (imgfile) - self.setpixmap (PIX) - #resize a control to a picture in self.resize (Pix.width (), Pix.height ()) - to + if __name__=='__main__': -App =qtgui.qapplication (SYS.ARGV) theA =Piclabel (imgfile) * a.show () $Sys.exit (App.exec_ ())
Pyside add a picture to a window