#-*-coding:cp936-*-
Import Sys
From PYQT4 import Qtcore, Qtgui
Class Mydialog (Qtgui.qdialog):
def __init__ (self, Parent=none):
Qtgui.qdialog.__init__ (self, parent)
Self.quit = Qtgui.qpushbutton ("Quit")
Self.change = Qtgui.qpushbutton ("Change")
Self.change.setEnabled (False)
# Funny Widget
SELF.LCD = Qtgui.qlcdnumber (2)
Self.slider = Qtgui.qslider (QtCore.Qt.Horizontal)
Self.slider.setRange (0, 99)
Self.slider.setValue (0) painter. Drawpixmap (target, image, source);
def paintevent (self,event):
painter = Qpainter (self)
Painter.drawpixmap (0,0,280,390,qpixmap ("1.png"))
Painter.drawpixmap (300,0,280,390,qbitmap ("1.png"))
Self.pix = Qpixmap ("1.png")
Self.resize (Self.pix.size ())
Self.setmask (Self.pix.mask ())
Self.pix = Qbitmap ("2.png")
Self.resize (Self.pix.size ())
Self.setmask (Self.pix)
def paintevent (self,event):
painter = Qpainter (self)
Painter.drawpixmap (0,0,self.pix.width (), Self.pix.height (), Qpixmap ("3.jpg"))
LCD = Qtgui.qlcdnumber (self)
SLD = Qtgui.qslider (QtCore.Qt.Horizontal, self)
Sld.valueChanged.connect (Lcd.display)
Sender is the object that sends the signal. Receiver is the object that receives the signal. The slot is the method of feedback signal.
Overloaded methods
Import Sys
From PYQT4 import Qtgui, Qtcore
Class Example (Qtgui.qwidget):
def __init__ (self):
Super (Example, self). __init__ ()
Self.initui ()
def initui (self):
Self.setgeometry (300, 300, 250, 150)
Self.setwindowtitle (' Event handler ')
Self.show ()
def keypressevent (self, e): #这个表示重载方法
If E.key () = = QtCore.Qt.Key_Escape:
Self.close ()
def main ():
App = Qtgui.qapplication (SYS.ARGV)
ex = Example ()
Sys.exit (App.exec_ ())
if __name__ = = ' __main__ ':
Main ()
In our example, we re-implemented the Keypressevent ().
def keypressevent (self, E):
If E.key () = = QtCore.Qt.Key_Escape:
Self.close ()
Sender () method knows the source of the message
def buttonclicked (self):
Sender = Self.sender ()
Self.statusbar (). ShowMessage (Sender.text () + ' was pressed ')
Self.statusbar (). ShowMessage (' ready ') status bar
A component (widget) is the most basic component of an application. There are a number of components in the PYQT4. Buttons, selection boxes, sliders, lists, etc.
Cb.toggle ()
We set the title of the window, so we must check the selection box. By default, the title of the window is not set and the selection box is not checked.
Self.lineedit = Qtgui.qlineedit ()
Self.connect (Self.quit, Qtcore.signal ("clicked ()"),
Qtgui.qapp, Qtcore.slot ("Quit ()"))
Self.connect (Self.lineedit, Qtcore.signal ("textChanged (const qstring&)"),
Self.enablechangebutton)
Self.connect (Self.slider, Qtcore.signal ("valuechanged (int)"),
Self. Sliderchange)
Self.connect (Self.change, Qtcore.signal ("clicked ()"),
Self. Change)
Self.rightlayout = Qtgui.qvboxlayout ()
Self.rightLayout.addWidget (Self.lineedit)
Self.rightLayout.addWidget (Self.change)
Self.leftlayout = Qtgui.qvboxlayout ()
Self.leftLayout.addWidget (SELF.LCD)
Self.leftLayout.addWidget (Self.slider)
Self.layout = Qtgui.qhboxlayout ()
Self.layout.addWidget (Self.quit)
Self.layout.addLayout (Self.leftlayout)
Self.layout.addLayout (Self.rightlayout)
Self.setlayout (self.layout);
def enablechangebutton (self, text):
Self.change.setEnabled (text.isempty () = = False) #重点
def change (self):
value = Int (Self.lineEdit.text ())
Self.lcd.display (value)
Self.slider.setValue (value)
def sliderchange (self):
Value = Self.slider.value ()
Self.lcd.display (value)
Self.lineEdit.setText (str (value))
App = Qtgui.qapplication (SYS.ARGV)
Dialog = Mydialog ()
Dialog.show ()
Sys.exit (App.exec_ ())
The Qlistview class provides a list or icon view to the model
The Qtreeview class provides a default model/view implementation in a tree view
The classes in Qtableview provide the default model/view Implementation table view.
The Qcolumnview class provides a model/view implementation in the column view
The Qtablewidget class provides a default model for item-based table views
The Qtreewidget class provides a tree view that uses predefined tree models
The Qlistwidget class provides an item-based list control
The Qdeclarativeview class provides a small tool to display a QT declarative user interface
The Qline class provides a two-dimensional vector using integer precision
Qprogressbar parts provide horizontal or vertical progress bars
The Qtextbrowser class provides a hypertext browsing format text browser
The Qcalendarwidget class provides a monthly per-calendar component that allows the user to select a date
Qlcdnumber plug-in plays with some LCD-like numbers
The Qgraphicsview class provides a small tool for displaying content Qgraphicsscene
The Qgraphicsscene class provides a surface for managing a large number of 2D graphics items
The Qlabel widget provides a display of text or images
The Videoplayer control is used for video playback
The Volumeslider plug-in provides a slider to control the volume of the Audio output unit
The Seekslider class provides a slider for seeking position in the media stream
The Qwebview class provides a gadget for viewing and editing Web page files
and Qt.vertical | Qt.horizontal means it's going to grow in both areas
The Qgridlayout class outlines the parts in the grid
Formlayout,horizontallayout,verticallayout,verticalslider,horizontalslider,verticalscrollbar, Horizontalscrollbar document could not find information
The Qdialogbuttonbox class is a widget that renders in a layout that is appropriate for the current control style button
Qcommandlinkbutton Gadget provides Vista style command link button
The Qcheckbox control provides a check box for a text label
The Qtoolbutton class provides a quick Access button, command, or option that is typically used for internal qtoolbar
The Qtoolbar class provides a movable panel that contains a set of controls
The Qradiobutton gadget provides a radio button, a text label
The Qpushbutton widget provides a command button
The Qscrollarea class provides a scrolling view to another department
Qgroupbox Widget provides a grouped box frame with headings
The Qtoolbox class provides a column for a tabbed widget project
The Qtabwidget class provides a stack label part
The Qstackedwidget class provides a stacked part where only one part is visible at the same time
The Qaxwidget class is qwidget, and it wraps an ActiveX control
The Qdatetimeedit class provides an edit date and time for a part
The Qdial class provides a circular range control such as a speedometer or potentiometer
The Qtimeedit class provides a component based on the edit time Qdatetimeedit part
The Qdateedit class provides a small tool for editing date-based Qdatetimeedit parts
Qcombobox indicates that the widget is a key combination that pops up in the list
The Qfontcombobox widget is a combo box that lets the user select a font family
The Qtextedit class provides a rich text control for editing and displaying two plains
The Qplaintextedit class provides a gadget for editing and displaying plain text
The Qspinbox class provides a spinner control
The Qdoublespinbox class provides a spinner widget that requires double
Qlineedit Widget is a single-line text editor
PyQt Document Method Description (not highlighted)