-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustomerDefineQtClass.py
38 lines (36 loc) · 1.47 KB
/
customerDefineQtClass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from PyQt6.QtGui import QKeySequence
from PyQt6.QtWidgets import QKeySequenceEdit, QPlainTextEdit
from PyQt6.QtCore import pyqtSignal, Qt
class oneKeyQKeySequenceEdit(QKeySequenceEdit):
def __init__(self, parent=None):
super(oneKeyQKeySequenceEdit, self).__init__(parent)
self._string = ''
def keyPressEvent(self, QKeyEvent):
super(oneKeyQKeySequenceEdit, self).keyPressEvent(QKeyEvent)
value = self.keySequence()
self._string = self.keySequence().toString()
self.setKeySequence(value)
class betterSelectionQPlainTextEdit(QPlainTextEdit):
mouseRelease = pyqtSignal()
selectedFinish = pyqtSignal()
focusOut = pyqtSignal()
callContextMenu = pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent)
def mouseReleaseEvent(self,event):
super().mouseReleaseEvent(event)
self.mouseRelease.emit()
if(self.textCursor().hasSelection()):
self.selectedFinish.emit()
def focusOutEvent(self,event):
super().focusOutEvent(event)
self.focusOut.emit()
def clearSelection(self):
_cursor = self.textCursor()
self.selectionArea = _cursor.selectionEnd(), _cursor.selectionStart()
_cursor.clearSelection()
self.setTextCursor(_cursor)
def contextMenuEvent(self, e) -> None:
self.callContextMenu.emit()
_cursor = self.textCursor()
self.selectionArea = _cursor.selectionEnd(), _cursor.selectionStart()