From d724fbcffb4d566960205844abd1671bee272ea1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 4 Sep 2014 08:56:38 +0530 Subject: [PATCH] Workaround for Qt 5 bug that causes text copied to the clipboard to be lost when quitting the viewer on windows. https://bugreports.qt-project.org/browse/QTBUG-41125 --- src/calibre/gui2/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index bb20aea75f..16c97ba626 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -939,6 +939,20 @@ class Application(QApplication): p.setColor(p.Inactive, role, p.color(p.Active, role)) self.setPalette(p) + if iswindows: + # Prevent text copied to the clipboard from being lost on quit due to + # Qt 5 bug: https://bugreports.qt-project.org/browse/QTBUG-41125 + self.aboutToQuit.connect(self.flush_clipboard) + + def flush_clipboard(self): + try: + if self.clipboard().ownsClipboard(): + import ctypes + ctypes.WinDLL('ole32.dll').OleFlushClipboard() + except Exception: + import traceback + traceback.print_exc() + def load_builtin_fonts(self, scan_for_fonts=False): if scan_for_fonts: from calibre.utils.fonts.scanner import font_scanner