Note that there are some explanatory texts on larger screens.

plurals
  1. POEdit QGraphicsTextItem inside QGraphicsItemGroup
    primarykey
    data
    text
    <p>I want a python application that displays a bunch of small portraits and a names below it. Like that: <img src="https://i.stack.imgur.com/iBwoW.png" alt="This is how the application looks like"></p> <p>They should be movable and editable (by double clicking the text).</p> <p>I am using PyQt4 so I figured out, it would be easiest to use a <code>QGraphicsView</code> and a <code>QGraphicsScene</code> for the canvas. So I subclassed a <code>QGraphicsItemGroup</code> like this:</p> <pre><code>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) </code></pre> <p>But there are some Problems:</p> <ul> <li>Text editing is triggered by a single click, but I want double click (Might be a duplicate of <a href="https://stackoverflow.com/questions/10235411/qgraphicstextitem-editable-only-after-double-mouse-click">this</a>).</li> <li>You can't use the mouse to select text or move the cursor because the whole group is moved then.</li> <li>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) </li> </ul> <p>I tried to catch the double click signal and switch to an edit mode that forwards the all the mouse events to the text. But I wasn't able to <em>activate</em> the editing process with the double click and furthermore I couldn't preserve the behavior to end the editing by clicking somewhere else.</p> <p>So I hope someone can help me. It might be enough to know how to manually activate and deactivate the text interaction mode of the <code>QGraphicsTextItem</code>. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload