* Improved mouse-over kanji detection in word dic results.
authorUrban Wallasch <urban.wallasch@freenet.de>
Thu, 24 Jun 2021 15:03:48 +0000 (17:03 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Thu, 24 Jun 2021 15:03:48 +0000 (17:03 +0200)
jiten-pai.py

index 2b2496134da91fd7a1a6c51cf414fc33edbe92e3..794829ae607c88083b2eca2723fc8917cb190952 100755 (executable)
@@ -427,14 +427,15 @@ class zQTextEdit(QTextEdit):
             self.app.restoreOverrideCursor()
 
     def mouseMoveEvent(self, event):
-        pos = event.pos()
-        pos.setX(pos.x() - 15)
         scr = self.verticalScrollBar().value()
         old_tcur = self.textCursor()
-        tcur = self.cursorForPosition(pos)
+        cwidth = QFontMetrics(QFont(cfg['lfont'], cfg['lfont_sz'])).horizontalAdvance('範')
+        tcur = self.cursorForPosition(QPoint(event.pos().x() - cwidth/2, event.pos().y()))
         self.setTextCursor(tcur)
-        tcur.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor);
-        char = tcur.selectedText()
+        char = ''
+        if not (tcur.atBlockStart() and event.pos().x() - self.pos().x() > cwidth):
+            tcur.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor);
+            char = tcur.selectedText()
         self.setTextCursor(old_tcur)
         self.verticalScrollBar().setValue(scr)
         if is_kanji(char):