Results 1 to 4 of 4

Thread: QGraphicsItem visible in only one QGraphicsView and hidden in the other

  1. #1
    Join Date
    Jan 2011
    Location
    Netherlands
    Posts
    17
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsItem visible in only one QGraphicsView and hidden in the other

    I have a QGraphicsScene which I populate with QGraphicsItems. Next I have two QGraphicsViews, one acting as the main view and the other as an overview. Both QGraphicsViews scenes are set with the same scene. Now I want to have a special QGraphicsItem which is visible in the overview QGraphicsView but is not visible in the mainviews QGraphicsView.

    How can I achieve this? Currently the item is added to the scene and I see it in both views. I can hide it but then it is hidden in both views.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem visible in only one QGraphicsView and hidden in the other

    You might be able to leverage the view's drawItems() function. Generally, though, this sounds like a bad idea. You might also have a look at the view's drawForeground and drawBackground functions, depending on what it is you're trying to accomplish.

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

    Stef (7th February 2011)

  4. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGraphicsItem visible in only one QGraphicsView and hidden in the other

    QGraphicsScene has a virtual "drawItems" method, its last parameter is a "pointer to the widget that is being painted on". I think by default it points to QGraphicsView::viewport() widget, maybe you could use this information somehow to distinguish between main view and the overview.

  5. The following user says thank you to stampede for this useful post:

    Stef (7th February 2011)

  6. #4
    Join Date
    Jan 2011
    Location
    Netherlands
    Posts
    17
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem visible in only one QGraphicsView and hidden in the other

    Quote Originally Posted by SixDegrees View Post
    You might be able to leverage the view's drawItems() function. Generally, though, this sounds like a bad idea. You might also have a look at the view's drawForeground and drawBackground functions, depending on what it is you're trying to accomplish.
    Thank you very much for the fast replies, SixDegrees and stampede

    drawForeground was exactly what I was looking for! Don't know how I've missed it. Thanks again!

Similar Threads

  1. Replies: 2
    Last Post: 16th July 2010, 13:42
  2. qwidget how to set visible/hidden ?
    By ricky in forum Newbie
    Replies: 4
    Last Post: 12th August 2009, 08:07
  3. Replies: 1
    Last Post: 16th July 2009, 16:58
  4. get all QListWidgetItem*(visible and hidden )
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2006, 22:02
  5. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00

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.