PYTHON-PYQT4 Study Notes

Source: Internet
Author: User

1. Each app must create a qtgui.qapplication (SYS.ARGV), at which point Qtgui.qapp an instance of this app

App =# because exec is a keyword, so Qt uses the exec_, APP.EXEC_ () to represent a loop into the

2. All interface graphics classes are inherited from Qtgui.qwidget, such as Qtgui.qpushbutton can use Setgeometry () and other methods, Qwidget If the parent is not specified, then it is the top-level window a

3.qtgui.qpushbutton (' Quit ', widget), create a Qpushbutton instance, put it on the widget

The 4.pyqt4 event processing system is based on the signal-slot

The slot details can be referenced in the following two articles, PYQT4 signal and Groove usage summary, signal and slot details

The signal and slot mechanism, as the most important feature of QT, provides a communication mechanism between any two Qt objects, which is triggered by a particular case or action, and the slot is a function for receiving and processing the signal.

Each Qt object contains predetermined signals and slots, and when a particular event occurs, a signal is emitted, and the slot associated with the signal responds to the signal to complete the corresponding processing

The signal-to-slot mechanism is commonly connected by connect (object1,signal (SIGNAL), Object2,slot (slot)), where the slot function can be a slot function that comes with PyQt, or a custom slot function (@ Qtcore.pyqtslot ()), or even any function that can be called by Python

W.connect (BTN, Qtcore.signal ("clicked ()"), Qtgui.qapp, Qtcore.slot ("Quit ( )"))

Or

#Coding:utf-8 fromPyQt4ImportQtgui, Qtcoreapp=qtgui.qapplication ([]) W=Qtgui.qwidget ()defshowmsg (): QtGui.QMessageBox.information (w, u"Information"+ R"OK") btn= Qtgui.qpushbutton (U"Point Me", W) w.connect (BTN, Qtcore.signal ("clicked ()"), showmsg)#or Btn.clicked.connect (showmsg)w.show () app.exec_ ( )

The clicked () signal of the button object is connected to the SHOWMSG function, which means that showmsg responds to a button's Click event

Aa

PYTHON-PYQT4 Study Notes

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.