pyqt6: Fix drop and hover events as well

This commit is contained in:
Kovid Goyal 2022-01-01 22:38:50 +05:30
parent f2c058fea3
commit a5257b532f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 8 additions and 4 deletions

View File

@ -232,7 +232,7 @@ class ToolBar(QToolBar): # {{{
# support drag&drop from/to library, from/to reader/card, enabled plugins
def check_iactions_for_drag(self, event, md, func):
if self.added_actions:
pos = event.pos()
pos = event.position().toPoint()
for iac in itervalues(self.gui.iactions):
if iac.accepts_drops:
aa = iac.qaction

View File

@ -232,7 +232,7 @@ def dropEvent(self, event):
md = event.mimeData()
if dnd_merge_ok(md):
ids = set(map(int, filter(None, bytes(md.data('application/calibre+from_library')).decode('utf-8').split(' '))))
row = self.indexAt(event.pos()).row()
row = self.indexAt(event.position().toPoint()).row()
if row > -1 and ids:
book_id = self.model().id(row)
if book_id and book_id not in ids:

View File

@ -61,7 +61,7 @@ class HeaderView(QHeaderView): # {{{
def event(self, e):
if e.type() in (QEvent.Type.HoverMove, QEvent.Type.HoverEnter):
self.hover = self.logicalIndexAt(e.pos())
self.hover = self.logicalIndexAt(e.position().toPoint())
elif e.type() in (QEvent.Type.Leave, QEvent.Type.HoverLeave):
self.hover = -1
return QHeaderView.event(self, e)

View File

@ -10,7 +10,7 @@ from qt.core import (
QAbstractItemView, QAction, QComboBox, QDialog, QDialogButtonBox, QDrag,
QEventLoop, QFontMetrics, QFormLayout, QFrame, QImage, QIODevice, QLineEdit,
QMenu, QMessageBox, QModelIndex, QPalette, QSinglePointEvent, Qt, QThread,
QToolButton, QEvent
QToolButton, QEvent, QDropEvent, QHoverEvent
)
from calibre_extensions import progress_indicator
@ -24,6 +24,10 @@ QSinglePointEvent.globalY = lambda self: self.globalPosition().toPoint().y()
QSinglePointEvent.localPos = lambda self: self.position()
QSinglePointEvent.screenPos = lambda self: self.globalPosition()
QSinglePointEvent.windowPos = lambda self: self.scenePosition()
QDropEvent.pos = lambda self: self.position().toPoint()
QDropEvent.posF = lambda self: self.position()
QHoverEvent.pos = lambda self: self.position().toPoint()
QHoverEvent.posF = lambda self: self.position()
# Restore the removed exec_ method