明霞山资源网 Design By www.htccd.com
问题背景
上图中的红色框框就是在QLabel
的基础上实现的功能。
实现思路
"htmlcode">
from PyQt5.QtWidgets import QLabel from PyQt5.QtCore import Qt,QRect from PyQt5.QtGui import QPainter,QPen class Label(QLabel): x0=0 y0=0 x1=0 y1=0 open_mouse_flag=False select_roi_flag=False draw_roi_flag=False clear_flag=False rect = QRect() #按下鼠标 def mousePressEvent(self, event): if self.open_mouse_flag is True: self.select_roi_flag=True self.x0=event.x() self.y0=event.y() #释放鼠标 def mouseReleaseEvent(self, event): self.select_roi_flag=False #移动鼠标 def mouseMoveEvent(self, event): if self.select_roi_flag is True: self.x1=event.x() self.y1=event.y() if self.draw_roi_flag is True: self.update() #绘制事件 def paintEvent(self,event): super().paintEvent(event) painter = QPainter(self) painter.setPen(QPen(Qt.red, 5, Qt.SolidLine)) if self.clear_flag is True: self.x0=0 self.y0=0 self.x1=0 self.y1=0 self.rect = QRect(self.x0, self.y0, abs(self.x1 - self.x0), abs(self.y1 - self.y0)) painter.drawRect(self.rect) self.update()
其他要注意的问题
"htmlcode">
# 清除label对象的绘制内容 def clear_label(self): self.label_show.clear_flag = True self.label_show.clear()
"htmlcode">
# 重写键盘事件 def keyPressEvent(self, QKeyEvent): if self.open_keyboard_flag is True: # 当键盘事件为真的是才有键盘事件监控 if QKeyEvent.key() == Qt.Key_S: self.label_show.setCursor(Qt.CrossCursor) # 切换游标为十字型 self.label_show.open_mouse_flag = True self.label_show.draw_roi_flag = True if QKeyEvent.key() == Qt.Key_Q: # 按下'q'键键盘监控关闭 self.label_show.unsetCursor() self.label_show.draw_roi_flag = False self.label_show.open_mouse_flag = False self.open_keyboard_flag = False
明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。