Results 1 to 3 of 3

Thread: QGraphicsItem always selected

  1. #1
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsItem always selected

    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:
    Qt Code:
    1. 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.
    Qt Code:
    1. def paint(self, painter, option, widget):
    2. if option.state and QtGui.QStyle.State_Selected:
    3. 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:
    Qt Code:
    1. 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:
    Qt Code:
    1. if option.state and QtGui.QStyle.State_Selected:
    2. painter.setPen(QtCore.Qt.green)
    3. painter.setBrush(QtCore.Qt.NoBrush)
    4. 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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem always selected

    Is "and" a bitwise or a bytewise operator in Python? By quickly inspecting Python docs it seems you should use "&" instead of "and".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    prashant (29th September 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem always selected

    Thanks......

Similar Threads

  1. Replies: 2
    Last Post: 25th March 2011, 09:18
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. How to get parent of selected item in TreeView?
    By RavenS in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2009, 13:27
  4. Replies: 1
    Last Post: 25th February 2009, 00:34
  5. deleting selected headers
    By ru_core in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2008, 07:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.