PDA

View Full Version : QGraphicsItem always selected



prashant
29th September 2009, 03: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

wysota
29th September 2009, 10:12
Is "and" a bitwise or a bytewise operator in Python? By quickly inspecting Python docs it seems you should use "&" instead of "and".

prashant
29th September 2009, 12:56
Thanks......:)