-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreplaceText.py
More file actions
32 lines (26 loc) · 1.09 KB
/
replaceText.py
File metadata and controls
32 lines (26 loc) · 1.09 KB
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
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QTextEdit, QMenu
from PyQt6.QtGui import QAction
from PyQt6.QtCore import Qt # Add this import
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Text Replacement App")
self.setGeometry(100, 100, 400, 300)
self.text_edit = QTextEdit(self)
self.setCentralWidget(self.text_edit)
self.text_edit.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) # Updated this line
self.text_edit.customContextMenuRequested.connect(self.show_context_menu)
def show_context_menu(self, pos):
context_menu = QMenu(self)
prompt_action = QAction("sdkfsdf", self)
prompt_action.triggered.connect(self.replace_text)
context_menu.addAction(prompt_action)
context_menu.exec(self.text_edit.mapToGlobal(pos))
def replace_text(self):
self.text_edit.setPlainText('hello')
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())