Results 1 to 10 of 10

Thread: More on selective QGraphicsItem visibility

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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 More on selective QGraphicsItem visibility

    OK, in follow-up to my previous post, I have refactored my data plotting widget so that it uses a QGraphicsView instance only for the part of the plot that displays the data itself. The axes, titles, footers, etc. are displayed using QwtScaleWidget, QLabel, etc.

    One of the characteristics of this plot is that labels for the data points are drawn so that they don't collide or overlap, and that the size of the label does not scale (remains a fixed size) when the plot is zoomed in or out. This is accomplished with the ItemIgnoresTransformations flag.

    I have also implemented view-based collision detection: I create the candidate set of labels based on the zoom region in the view, then map the label positions and sizes from scene to view. I then go through this list and check for collisions; for any colliding pair of labels, the one with the lower z-value is made invisible. All of this works fine.

    The way I am trying to realize this on screen is to overlay two QGraphicsView windows. One window contains the data and its plot, the other contains only the labels. There are two QGraphicsScene instances, one for the data and plot, the other for the labels. The data scene can be shared among multiple plots, which allows me to display one in 1:1 format, the other zoomed in or out, etc. without having to duplicate the underlying data or scene objects. The label scene is dedicated to the QGraphicsView that displays the labels. In this way, two views of the same scene could have a different set of non-colliding labels, as a sort of "level of detail" effect.

    The problem I am having is that I cannot seem to make both graphics views simultaneously visible. I have tried various versions of this code in my plot widget constructor:

    Qt Code:
    1. mpCanvas = new QGraphicsView( this );
    2. mpCanvas->setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
    3. mpCanvas->setEnabled( true );
    4. mpCanvas->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    5. mpCanvas->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    6. mpCanvas->setWindowOpacity( 0.0 );
    7. mpCanvas->setBackgroundBrush( Qt::NoBrush );
    8.  
    9. mpLabelCanvas = new QGraphicsView( &mLabelScene, this );
    10. mpLabelCanvas->setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
    11. mpLabelCanvas->setEnabled( false );
    12. mpLabelCanvas->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    13. mpLabelCanvas->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    14.  
    15. mpLabelCanvas->stackUnder( mpCanvas );
    To copy to clipboard, switch view to plain text mode 

    where "mpCanvas" is the QGraphicsView that uses the shared QGraphicsScene containing the data, and "mpLabelCanvas" is the QGraphicsView with the dedicated scene holding the labels. (Scenes are assigned later in the constructor, and labels are calculated on-the-fly during resize and zoom operations).

    In the version posted above, the "mpCanvas" is visible, the "mpLabelCanvas" is not. (I see the data but no labels). If I stack them the other way, the opposite occurs, so I know that I am positioning, sizing, and setting transforms for the two views correctly.

    What I want to happen is that the upper (data) view is transparent so that the lower (label) view shows through it. This is my last hurdle in getting this widget to a state where I can actually write the app that uses it.

    Is there some combination of window flags, opacity, background brush, etc. that will create this effect?
    Last edited by d_stranz; 12th February 2013 at 21:19.

Similar Threads

  1. Replies: 2
    Last Post: 1st February 2013, 20:59
  2. Selective signaling
    By csaken in forum Qt Programming
    Replies: 15
    Last Post: 30th April 2010, 09:13
  3. Visibility with styleSheets
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 21st January 2010, 11:14
  4. QTabWidget tab visibility
    By dcss-design in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2007, 23:24
  5. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20

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.