PYQT Event Filter Usage (eventfilter) (not very clear)

Source: Internet
Author: User

Use of the PyQt event filter (EventFilter)

Read 13 times 2014/8/5 19:47:24

#-*-coding:cp936-*-

#由于现在不是很明白: The Use of event filters (EventFilter), the first collection

From PYQT4 import Qtgui, Qtcore

Class Window (Qtgui.qmainwindow):

def __init__ (self):

Qtgui.qmainwindow.__init__ (self)

Widget = Qtgui.qwidget (self)

Layout = Qtgui.qvboxlayout (widget)

Self.edit = Qtgui.qlineedit (self)

Self.list = Qtgui.qlistwidget (self)

Layout.addwidget (Self.edit)

Layout.addwidget (Self.list)

Self.setcentralwidget (widget)

Self.edit.installEventFilter (self) #在窗体上为self. Edit Install Filter

#QEvent:: Focusin (get focus event)

"""

Qpalette P=qpalette ();

P.setcolor (Qpalette::base,qt::green);

Ui->lineedit1->setpalette (P);

Qevent::focusout loses focus

"""

Self.list.installEventFilter (self)

def eventfilter (self, Source, event):

If event.type () = = QtCore.QEvent.MouseMove:

If event.buttons () = = QtCore.Qt.NoButton:

pos = Event.pos ()

Self.edit.setText (' x:%d, y:%d '% (pos.x (), Pos.y ()))

Else

Pass # do other stuff

Return QtGui.QMainWindow.eventFilter (self, source, event) #将事件交给上层对话框

if __name__ = = ' __main__ ':

Import Sys

App = Qtgui.qapplication (SYS.ARGV)

Win = Window ()

Win.show ()

App.installeventfilter (Win)

Sys.exit (App.exec_ ())

PYQT Event Filter Usage (eventfilter) (not very clear)

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.