Hi,
This is related to PyQt and I am kind of beginner here.
To show a that particular QGraphicsItem is selected you have to set a property:
self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable)
To copy to clipboard, switch view to plain text mode
and in "paint" event, you can draw something to show that item has been selected.
def paint(self, painter, option, widget):
if option.
state and QtGui.
QStyle.
State_Selected: painter.setPen(QtCore.Qt.green)
def paint(self, painter, option, widget):
if option.state and QtGui.QStyle.State_Selected:
painter.setPen(QtCore.Qt.green)
To copy to clipboard, switch view to plain text mode
It looks pretty easy but it is not working as it has to. To confirm that I did some changes in the example graphicsview>elasticnodes.pyw that comes with PyQt and eventually I encountered the same problem there also.
First change is to add property:
self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable)
To copy to clipboard, switch view to plain text mode
and second change is to draw something is paint event:
if option.
state and QtGui.
QStyle.
State_Selected: painter.setPen(QtCore.Qt.green)
painter.setBrush(QtCore.Qt.NoBrush)
painter.drawRect(0,0, 10, 10)
if option.state and QtGui.QStyle.State_Selected:
painter.setPen(QtCore.Qt.green)
painter.setBrush(QtCore.Qt.NoBrush)
painter.drawRect(0,0, 10, 10)
To copy to clipboard, switch view to plain text mode
and resulting image is:
As you can see there are small green color rectangles on every node.
Is it a bug? Is there any property of QGraphicsView that needs to be set/unset to resolve this problem?
Cheers
Prashant
Python 2.5.2
PyQt-Py2.5-gpl-4.4.3-1
Win XP, 32 Bit
Bookmarks