I want a python application that displays a bunch of small portraits and a names below it. Like that:
它们应是可移动和可编辑的(双击文本)。
我使用 PyQt4, 所以我想通了, 在画布上使用 < code'graphicsView 和 < code'graphicsSceen 比较容易。 所以我将这样的 < code'graphicsTroup 分类为 < code'graphicsTroup :
from PyQt4 import QtCore, QtGui
class Speaker(QtGui.QGraphicsItemGroup):
def __init__(self, name, parent=None):
QtGui.QGraphicsItemGroup.__init__(self, parent)
self.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
self.text = QtGui.QGraphicsTextItem(name)
self.text.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction)
self.addToGroup(self.text)
self.portrait = QtGui.QGraphicsPixmapItem(QtGui.QPixmap("portrait.png"))
self.portrait.setY(-35)
self.addToGroup(self.portrait)
def keyPressEvent(self, QKeyEvent):
# Forwarding KeyPress events to the text to enable text editing
self.text.keyPressEvent(QKeyEvent)
但有些问题:
- Text editing is triggered by a single click, but I want double click (Might be a duplicate of this).
- You can t use the mouse to select text or move the cursor because the whole group is moved then.
- If you stop the editing the cursor won t disappear. (Though I know how to do that, if I find a way to activate and deactivate editing mode)
我试图抓取双击信号, 并切换到一个将所有鼠标事件都转发到文本的编辑模式。 但我无法用双击来“ 激活 < / em > 编辑进程 ” 。 此外, 我无法保留通过点击别处结束编辑的行为 。 @ info/ plain
所以,我希望有人能帮我。也许就足够知道如何手动激活和禁用“GraphicsTextTextTroject ”的文本互动模式了。谢谢!