Pyside add a picture to a window

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.