[Python] PyQt clipboard doesn't copy to system clipboard

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    The following snippet of code doesn't seem to affect the system clipboard at all:

    clipboard = QtGui.QApplication.clipboard()
    clipboard.setText(text)


    According to the Qt documentation, this is how you copy text to clipboard,

    Why isn't it working?

    Googling turned this up.

    It suggests adding this after the above code:

    event = QtCore.QEvent(QtCore.QEvent.Clipboard)
    app.sendEvent(clipboard, event)


    But this one behaves odd: it only copies the text to the clipboard after the program exits. Plus, some people in that link reported that this doesn't work with linux.

    UPDATE:


    Nevermind, I was doing something wrong else where, instead of binding the copy slot to the copy button, I connected it to the "quit" button.

    Continue reading...

Compartilhe esta Página