Results 1 to 12 of 12

Thread: I cannot get QGraphicsRectItem to change colour on mousedoubleclickevent

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: I cannot get QGraphicsRectItem to change colour on mousedoubleclickevent

    if (CORE::castPtrType<C2DM::LinkState>(m_pLinkStateLi stModel->getTitle(indexOfShape)))// getTitle is looking for the index clicked
    Why do you think that the scene index returned in the QList is a constant that won't change? The scene could change the order of items in it based on the current stacking order of things in the scene, and the order can change as you add new items to the scene. And if you have QGraphicsLineItem, QGraphicsTextItem, and QGraphicsRectItem instances in the scene, all of these will have an index, too, and the index will depend on where they are in the hierarchy of scene objects.

    The only way you can guarantee that you can look up something by an index number is if you assign the index number yourself. The easiest way to do this is to use the mechanism you are already using on your rect objects: use another setData() property to assign the index to your rects. If you are using the key "0" already, then use a different key (1) to assign an index when you create the rect. If you are only indexing the rects, then start at index 0 and increment as you add new rects.

    If you ever delete a rect, then you will have to make sure that your model and your rects remain consistent - if you remove a rect with index 42, because you have removed the title with index 42, then you have to make sure that you either re-index everything from 42 up or access title <---> rect relationship in a way that is not affected by missing index numbers. Once again, an std:: map<> would work great for this.
    Last edited by d_stranz; 6th February 2020 at 18:03.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 6
    Last Post: 11th January 2012, 10:11
  2. Change the colour of a table view row
    By Splatify in forum Newbie
    Replies: 0
    Last Post: 7th March 2011, 06:31
  3. Change the colour of a QT TextEdit row
    By Splatify in forum Newbie
    Replies: 3
    Last Post: 3rd March 2011, 14:09
  4. Replies: 2
    Last Post: 3rd May 2010, 12:18
  5. Change colour of QString
    By Morea in forum Newbie
    Replies: 9
    Last Post: 10th February 2006, 22:31

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
  •  
Qt is a trademark of The Qt Company.