Workaround for Qt 5 bug that prevents using the return key to edit table cells in the main book list

https://bugreports.qt-project.org/browse/QTBUG-40938
This commit is contained in:
Kovid Goyal 2014-08-23 18:57:48 +05:30
parent 6866597563
commit e9080a686b

View File

@ -24,7 +24,7 @@ from calibre.gui2.library.alternate_views import AlternateViews, setup_dnd_inter
from calibre.utils.config import tweaks, prefs
from calibre.gui2 import error_dialog, gprefs, FunctionDispatcher
from calibre.gui2.library import DEFAULT_SORT
from calibre.constants import filesystem_encoding
from calibre.constants import filesystem_encoding, isosx
from calibre import force_unicode
class HeaderView(QHeaderView): # {{{
@ -1061,6 +1061,18 @@ class BooksView(QTableView): # {{{
def row_count(self):
return self._model.count()
if isosx:
# Qt 5 item view handling of return key on OS X seems to be broken
# See https://bugreports.qt-project.org/browse/QTBUG-40938
def keyPressEvent(self, ev):
if ev.key() in (Qt.Key_Enter, Qt.Key_Return) and self.state() != self.EditingState:
ci = self.currentIndex()
if ci.isValid() and ci.flags() & Qt.ItemIsEditable:
if self.edit(ci, self.EditKeyPressed, ev):
ev.accept()
return
return QTableView.keyPressEvent(self, ev)
# }}}
class DeviceBooksView(BooksView): # {{{