Important: Please read the Qt Code of Conduct -

cannot get clipboard text using QClipboard on Android when App in background

  • I am using the following code to retrieve clipboard text once clipboard data changed on Android

    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    class EngkuDict(QLabel):
        # Permissions QFile::​permissions() const
        def __init__(self, parent=None):
            self.clipboard = QGuiApplication.clipboard()
            # self.clipboard.changed.connect(self.clipboardModeChanged)
        def clipboardTextChanged(self):
            selectedText = self.clipboard.text()
            self.setText('clipboardTextChanged: {}'.format(selectedText))
        def clipboardModeChanged(self, mode):
            selectedText = self.clipboard.text()
            self.setText('mode: {}\n{}'.format(mode, selectedText))
    if __name__ == "__main__":
        import sys
        app = QApplication(sys.argv)
        # QApplication.setQuitOnLastWindowClosed(False)
        trayIcon = EngkuDict()

    when the code is running in background, I copied text in another application, this application just cannot get clipboard text, so how to solve the issue ?

  • Moderators

    Add a slot handling for QGuiAppllication::applicationStateChanged. When it changes to Qt::ApplicationActive, call QClipboard::text() to update the value.

  • Thanks ! But I want it to work constantly in the background even when not activated .

  • Lifetime Qt Champion

    @redstoneleo Apps in background are stopped, aren't they? You would need a background service.

Log in to reply