Copy/Paste Hotkeys Not Working in Python Panel

   2946   4   2
User Avatar
Member
184 posts
Joined: 12月 2011
オフライン
So I built a custom asset manager panel based on the tutorials by Varomix and have noticed that houdini 16.0 doesn't seem to understand when I bring the panel into focus. This results in me being unable to use hotkeys to paste, copy, or cut text in the QLineEdit fields, although surprisingly command-Z still works for undoing changes. Instead, houdini tends to paste any relevant information in my clipboard into the last non-python window I had active.

Any ideas how to fix this? For now I am stuck using the right-click context menu to do these operations.
User Avatar
Member
184 posts
Joined: 12月 2011
オフライン
So I am still trying to figure out this issue. I've tried forcing the QLineEdit to be in focus, but Houdini is still intercepting my keyboard's clipboard commands.

Below is the simple program I am running. Basically it is just a text field that I expect to be able to copy and paste from. Any idea what I am doing wrong?

from PySide2 import QtCore, QtWidgets


from PySide2 import QtCore, QtWidgets

class TextField(QtWidgets.QLineEdit):

    def __init__(self, parent):
        super(TextField, self).__init__(parent)

        self.setPlaceholderText('Hello World')
        self.setFocusPolicy(QtCore.Qt.StrongFocus)


class Example(QtWidgets.QWidget):

    def __init__(self):
        super(Example, self).__init__()

        tf = TextField(self)
        tf.move(30, 65)

        tf.setFocus()
Edited by NFX - 2018年1月22日 15:08:50
User Avatar
スタッフ
1495 posts
Joined: 7月 2005
オフライン
Hello,

By any chance are you running on a Mac? There's a known issue where the Mac menu bar in Houdini steals the copy and paste hotkeys from Python Panels.

Cheers,
Rob
User Avatar
Member
184 posts
Joined: 12月 2011
オフライン
Yep. I'm on a Mac.

So this is a bug then? Oh well. I guess I still have the option of copy pasting from the context menu.
User Avatar
Member
184 posts
Joined: 12月 2011
オフライン
It's been a few years since this was posted, but I recently ran into this issue again. Along with the context menu solution, I found this to work as well:

from PySide2 import QtWidgets, QtCore, QtGui

class CopyableTextEdit(QtWidgets.QTextEdit):
    def keyPressEvent(self, event):
        if event.matches(QtGui.QKeySequence.Copy):
            QtWidgets.QApplication.clipboard().setText(self.textCursor().selectedText())
            return
        if event.matches(QtGui.QKeySequence.Paste):
            self.insertPlainText(QtWidgets.QApplication.clipboard().text())
            return
        if event.matches(QtGui.QKeySequence.Cut):
            clip = self.textCursor().selectedText()
            QtWidgets.QApplication.clipboard().setText(clip)
            self.textCursor().removeSelectedText()
            return
        super(CopyableTextEdit, self).keyPressEvent(event)

import hou
hou.session.text_widget = CopyableTextEdit(parent=hou.qt.mainWindow())
hou.session.text_widget.setWindowFlags(QtCore.Qt.Window)
hou.session.text_widget.show()
hou.session.text_widget.setPlainText('Hello World!')
  • Quick Links