Reprint Address: http://blog.csdn.net/gumanren/article/details/6129416
The code is as follows:
1 #-*-coding:utf-8-*-2 ImportSYS3 ImportWin32ui4 ImportWin32gui5 fromPyQt4ImportQtcore6 fromPyQt4ImportQtgui7 classTestwindow (Qtgui.qmainwindow):8 def __init__(self):9Super (Testwindow, self).__init__()TenSelf.setgeometry (180.0, 130.0, 280.0, 200.0) One self.setmousetracking (True) ALarge, small = Win32gui. Extracticonex (R"Netbeans.exe", 0) - Win32gui. DestroyIcon (small[0]) -Self.pixmap = QtGui.QPixmap.fromWinHBITMAP (Self.bitmapfromhicon (Large[0]), 2) the -Self.pixmap.save ("A.ico","ico") - - defBitmapfromhicon (Self, hicon): +HDC =Win32ui. Createdcfromhandle (Win32gui. GetDC (0)) -hbmp =Win32ui. CreateBitmap () +Hbmp. CreateCompatibleBitmap (HDC, 32, 32) AHDC =HDC. CreateCompatibleDC () at HDC. SelectObject (hbmp) - HDC. DrawIcon ((0, 0), Hicon) - HDC. DeleteDC () - returnhbmp. GetHandle () - #PaintEvent Events - defpaintevent (Self, event): in #Palette palette Multiple pix display, -painter =Qtgui.qpainter () topalette =Qtgui.qpalette () +Palette.setbrush (Self.backgroundrole (), Qtgui.qbrush (Qtgui.qpixmap (SELF.PIXMAP)))#set a background picture - Self.setpalette (palette) the #The painter Drawing class displays only one * #Painter.begin (self) $ #painter.setrenderhint (QtGui.QPainter.Antialiasing)Panax Notoginseng #Painter.setpen (QtCore.Qt.NoPen) - #Painter.setbrush (Qtgui.qbrush (Qtgui.qcolor (255.0, 255.0, 255.0, 255.0), QtCore.Qt.SolidPattern)) the #Painter.drawrect (qtcore.qrect (0.0, 0.0, 280.0, 400.0)) + #Painter.drawpixmap (qtcore.qrect (0.0, 0.0, 32.0, 32.0), Self.pixmap) A #painter.end () the if __name__=="__main__": +App =qtgui.qapplication (SYS.ARGV) -MainWindow =Testwindow () $ mainwindow.show () $APP.EXEC_ ()
Display effect:
Python Win32API extract exe icons icon