mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Proper fix for closing completion popups when clicking on the drop down arrow of comboboxes that does not conflict with windows on-screen keyboard
This commit is contained in:
parent
493aa66f36
commit
60c327bde6
@ -10,8 +10,10 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
import sip
|
import sip
|
||||||
from PyQt5.Qt import (QLineEdit, QAbstractListModel, Qt, pyqtSignal, QObject, QKeySequence,
|
from PyQt5.Qt import (
|
||||||
QApplication, QListView, QPoint, QModelIndex, QFont, QFontInfo)
|
QLineEdit, QAbstractListModel, Qt, pyqtSignal, QObject, QKeySequence,
|
||||||
|
QApplication, QListView, QPoint, QModelIndex, QFont, QFontInfo,
|
||||||
|
QStyleOptionComboBox, QStyle, QComboBox, QTimer)
|
||||||
|
|
||||||
from calibre.constants import isosx, get_osx_version
|
from calibre.constants import isosx, get_osx_version
|
||||||
from calibre.utils.icu import sort_key, primary_startswith, primary_contains
|
from calibre.utils.icu import sort_key, primary_startswith, primary_contains
|
||||||
@ -258,11 +260,21 @@ class Completer(QListView): # {{{
|
|||||||
# See https://bugreports.qt-project.org/browse/QTBUG-41806
|
# See https://bugreports.qt-project.org/browse/QTBUG-41806
|
||||||
e.accept()
|
e.accept()
|
||||||
return True
|
return True
|
||||||
elif etype == e.MouseButtonPress:
|
elif etype == e.MouseButtonPress and not self.rect().contains(self.mapFromGlobal(e.globalPos())):
|
||||||
if not self.rect().contains(self.mapFromGlobal(e.globalPos())):
|
# A click outside the popup, close it
|
||||||
self.hide()
|
if isinstance(widget, QComboBox):
|
||||||
e.accept()
|
# This workaround is needed to ensure clicking on the drop down
|
||||||
return True
|
# arrow of the combobox closes the popup
|
||||||
|
opt = QStyleOptionComboBox()
|
||||||
|
widget.initStyleOption(opt)
|
||||||
|
sc = widget.style().hitTestComplexControl(QStyle.CC_ComboBox, opt, widget.mapFromGlobal(e.globalPos()), widget)
|
||||||
|
if sc == QStyle.SC_ComboBoxArrow:
|
||||||
|
QTimer.singleShot(0, self.hide)
|
||||||
|
e.accept()
|
||||||
|
return True
|
||||||
|
self.hide()
|
||||||
|
e.accept()
|
||||||
|
return True
|
||||||
elif etype in (e.InputMethod, e.ShortcutOverride):
|
elif etype in (e.InputMethod, e.ShortcutOverride):
|
||||||
QApplication.sendEvent(widget, e)
|
QApplication.sendEvent(widget, e)
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user