Results 1 to 2 of 2

Thread: Change color of non selected items in QGraphicsScene/View

  1. #1
    Join Date
    May 2012
    Posts
    9
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Change color of non selected items in QGraphicsScene/View

    I have an application using QGraphicsScene and QGraphicsItem and I can change the color of the selected/mouse-over items using QStyle::StateFlag-enum -let's say selected items turn to color Red-. What I would like to do is also change the color of items that have not been selected to some other color -let's say blue-. What would be the best way to do this? I thought of looking-up the selected items of the scene in the mouse release event -either via ctrl+click,click or rubber band select- and change color of all the items that are not in the selectedItems container of QGraphicsScene but I'm not exactly sure if it is the best way to do it. -By the way, when the scene is first drawn, the items should have their own colors and only turn to blue when a selection event is fired instead of being drawn blue with default not selected flag.- Thanks.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Change color of non selected items in QGraphicsScene/View

    Connect a slot to the QGraphicsScene::selectionChanged() signal. In the slot, retrieve the QList of selected items QGraphicsScene::selectedItems(). Use that list to change the colors. If you keep a copy of the previous selections (initially empty), then you can change the colors only for the items that are not common to the old and new selection lists for better efficiency.
    <=== 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.

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

    s7 (9th August 2012)

Similar Threads

  1. QGraphicsScene sorting selected items
    By akiross in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2011, 20:23
  2. How change selected item rectangle on QGraphicsScene
    By xray2000 in forum Qt Programming
    Replies: 1
    Last Post: 18th May 2010, 17:43
  3. Replies: 3
    Last Post: 22nd January 2010, 17:46
  4. background color of not selected tab
    By iridium in forum Qt Programming
    Replies: 0
    Last Post: 13th August 2009, 16:57
  5. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 23:25

Tags for this Thread

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.