from PyQt5 import QtCore
from PyQt5.QtWidgets import QTextEdit
class MyQTextEdit(QTextEdit):
"""description of class"""
#============================================================
def __init__(self):
super(MyQTextEdit,self).__init__()
self.zoomsize=2
self.ctrlPressed=False
def wheelEvent(self, event):#this is the rewrite of the function
if self.ctrlPressed: #if the ctrl key is pressed: then deal with the defined process
delta=event.angleDelta()
oriention= delta.y()/8
self.zoomsize=0
if oriention>0:
self.zoomsize+=1
else:
self.zoomsize-=1
self.zoomIn(self.zoomsize)
print(self.zoomsize)
else: #if the ctrl key isn't pressed then submiting the event to it's super class
return super().wheelEvent(event)
def keyReleaseEvent(self, QKeyEvent):
if QKeyEvent.key()==QtCore.Qt.Key_Control:
self.ctrlPressed=False
return super().keyReleaseEvent(QKeyEvent)
def keyPressEvent(self, QKeyEvent):
if QKeyEvent.key()==QtCore.Qt.Key_Control:
self.ctrlPressed=True
print("The ctrl key is holding down")
return super().keyPressEvent(QKeyEvent)
#============================================================
PyQT 5 QTextEdit實現Ctrl+鼠標滾動放大或縮小文本
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.