From e0ef0b4174e46df2d746f2d31f3aa0cf121fb716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Thu, 1 Aug 2024 23:08:39 +0800 Subject: [PATCH] alt --- LunaTranslator/LunaTranslator/gui/edittext.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/edittext.py b/LunaTranslator/LunaTranslator/gui/edittext.py index 977c2198..4bd38718 100644 --- a/LunaTranslator/LunaTranslator/gui/edittext.py +++ b/LunaTranslator/LunaTranslator/gui/edittext.py @@ -100,6 +100,23 @@ class edittext(saveposwindow): self.textOutput.setPlainText(sentence) +class ctrlenter(QPlainTextEdit): + enterpressed = pyqtSignal() + + def keyPressEvent(self, e): + if e.key() == Qt.Key_Return or e.key() == Qt.Key_Enter: + if ( + e.modifiers() == Qt.ControlModifier + or e.modifiers() == Qt.ShiftModifier + or e.modifiers() == Qt.AltModifier + ): + self.insertPlainText("\n") + else: + self.enterpressed.emit() + else: + super().keyPressEvent(e) + + @Singleton_close class edittrans(LMainWindow): @@ -133,12 +150,12 @@ class edittrans(LMainWindow): def setupUi(self): self.setWindowIcon(qtawesome.icon("fa.edit")) - self.textOutput = QPlainTextEdit(self) + self.textOutput = ctrlenter(self) qv = QHBoxLayout() w = QWidget() self.setCentralWidget(w) w.setLayout(qv) - + self.textOutput.enterpressed.connect(self.submitfunction) submit = LPushButton("确定") qv.addWidget(self.textOutput) qv.addWidget(