English 中文(简体)
编辑 Q GraphicsText From 中的 Q Graphics Text 项目
原标题:Edit QGraphicsTextItem inside QGraphicsItemGroup

I want a python application that displays a bunch of small portraits and a names below it. Like that: This is how the application looks like

它们应是可移动和可编辑的(双击文本)。

我使用 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 ”的文本互动模式了。谢谢!

问题回答

您也许应该拨打 QGraphics Troup: setHandles儿童节(假名) 。

见“SO”问题“与QGriphicsTroup的晚上





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签