prashant
29th September 2009, 02:39
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)
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)
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)
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)
and resulting image is:
http://img89.imageshack.us/img89/2016/testqw.th.jpg (http://img89.imageshack.us/i/testqw.jpg/)
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
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)
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)
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)
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)
and resulting image is:
http://img89.imageshack.us/img89/2016/testqw.th.jpg (http://img89.imageshack.us/i/testqw.jpg/)
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