【PyQt4 实例27】事件过滤器
来源:互联网 发布:阿里云国际版没信用卡 编辑:程序博客网 时间:2024/05/09 15:24
# -*- coding: utf-8 -*-from PyQt4.QtGui import *from PyQt4.QtCore import *import sysQTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))class EventFilter(QDialog): def __init__(self,parent=None): super(EventFilter,self).__init__(parent) self.setWindowTitle(self.tr("事件过滤器")) self.label1 = QLabel(self.tr("请点击")) self.label2 = QLabel(self.tr("请点击")) self.label3 = QLabel(self.tr("请点击")) self.LabelState = QLabel(self.tr("test")) self.image1 = QImage("image/butterfly.png") self.image2 = QImage("image/butterfly.png") self.image3 = QImage("image/butterfly.png") self.width = 600 self.height = 300 self.resize(self.width,self.height) self.label1.installEventFilter(self) self.label2.installEventFilter(self) self.label3.installEventFilter(self) mainLayout = QGridLayout(self) mainLayout.addWidget(self.label1,500,0) mainLayout.addWidget(self.label2,500,1) mainLayout.addWidget(self.label3,500,2) mainLayout.addWidget(self.LabelState,600,1) self.setLayout(mainLayout) def eventFilter(self,watched,event): if watched == self.label1: if event.type() == QEvent.MouseButtonPress: mouseEvent = QMouseEvent(event) if mouseEvent.buttons() == Qt.LeftButton: self.LabelState.setText(self.tr("Left mouse button pressed on left image")) elif mouseEvent.buttons() == Qt.MidButton: self.LabelState.setText(self.tr("Middle mouse button pressed on left image")) elif mouseEvent.buttons() == Qt.RightButton: self.LabelState.setText(self.tr("Right mouse button pressed on left image")) matrix = QMatrix() matrix.scale(0.8,0.8) tmp = self.image1.transformed(matrix) self.label1.setPixmap(QPixmap.fromImage(tmp)) if event.type() == QEvent.MouseButtonRelease: self.LabelState.setText(self.tr("Mouse button released from left image")) self.label1.setPixmap(QPixmap.fromImage(self.image1)) return QDialog.eventFilter(self,watched,event) app=QApplication(sys.argv)dialog=EventFilter()dialog.show()app.exec_()
0 0
- 【PyQt4 实例27】事件过滤器
- 【PyQt4 实例25】获得鼠标事件
- 【PyQt4 实例26】获得键盘事件
- Qt事件处理器和事件过滤器实例
- Qt事件处理器和事件过滤器实例
- Qt事件处理器和事件过滤器实例
- Qt事件处理器和事件过滤器实例
- PyQt4 单击事件
- PyQt4中自定义事件
- PyQt4 实例源码阅读
- pyqt4实例练习1
- pyqt4实例练习2
- PyQt4的事件与信号
- 详解Pyqt4事件和信号
- 【PyQt4实例9】橡皮筋线
- 【PyQt4实例10】地图浏览器
- 【PyQt4 实例24】文件浏览器
- PyQT4图形界面开发入门实例
- Java IO
- Android Search 有历史记录 逐字检查 清空历史
- jdk 十进制 minior.major
- Java调用XML的方法:DocumentBuilderFactory
- 设计原则之迪米特法则
- 【PyQt4 实例27】事件过滤器
- 软件项目量化管理(CMMI高成熟度)实践经验谈——之项目管理过程策划篇
- Coming Back
- Project Eluer - 16
- kaptcha验证码使用
- Java 定时任务系列(2)- Spring定时任务的几种实现
- 第六章 图
- Insertion Sort List
- 继承Application实现Android数据共享