Results 1 to 9 of 9

Thread: Issues with the Graphics View Framework

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Issues with the Graphics View Framework

    The Graphics View Framework is a great tool, but I think it is influenced too much by OpenGL or OpenInventor...

    The Qt's zoom effectively is a magnifier that magnifies everything. It is basically taking the screen dump and scale the whole things, just as scaling an QPixmap. By doing this, it doesn't improve the view resolution at all. The Qwt's realtime is really a good example on how zoom should work. Qt's current zooming feature is not useful at all at this point.

    No one uses Inventor for 2D display in commercial software. In Qt, when we zoom a particular part of a plot area, such as a cross-plot showing with markers, we want to see the data clear separation. But if everything is magnified as if it is a QPixmap, we won't get any improvement in the resolution. One can just achieve this by changing the computer monitor's resolution, for instance, from 1920 x 1200 to 320 x 320....

    Any comment?

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

    Default Re: Issues with the Graphics View Framework

    Funny you say that... For me the zooming functionality does exactly what I think it should do - it... zooms And it surely doesn't improve resolution as the device you are painting on has a finite and fixed resolution so there is no way you can ever get a greater resolution. What graphics view does is that it delays translation from logical (real) to device (integer) coordinates and that's exactly what zooming is. Zooming doesn't increase resolution of the output, it makes things bigger (or smaller) using a fixed resolution - just like a photo camera - by zooming in you limit the area that is visible and extend it to the whole viewport, but the grain of the film remains the same. It is true you see more details of the viewed object and in these terms the resolution increases. That's exactly the same with graphics view.

    And you are wrong with your last sentence I think it comes from the probable fact that you do something wrong in your code and you think it has to be that way. Just launch the "chip" demo from Qt, play with it (especially with zooming and rotation) and read again your last sentence. This is the next time you are wrong with your statements about graphics view. It's high time you came to a conclusion it is actually worth reading the available documentation on the subject before making such strong statements.

    Here is a small demo related to "resolution".
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class ResItem : public QGraphicsRectItem {
    4. public:
    5. ResItem() : QGraphicsRectItem(){}
    6.  
    7. void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ){
    8. QPen p = painter->pen();
    9. p.setCosmetic(true);
    10. painter->setPen(p);
    11. QGraphicsRectItem::paint(painter, option, widget);
    12. qreal lod = option->levelOfDetail;
    13. qreal left = rect().left();
    14. qreal wid = rect().width();
    15. if(lod>=0.2)
    16. for(qreal i = 0; i<wid;i+=10.0){
    17. painter->drawLine(QLineF(left+i, rect().bottom(), left+i, rect().bottom()-10));
    18. if(lod>=1.0){
    19. for(qreal j = 1.0; j<5; j+=1.0){
    20. painter->drawLine(QLineF(left+i+2*j, rect().bottom(), left+i+2*j, rect().bottom()-5));
    21. if(lod>=4){
    22. for(qreal k = 0.4; k<2.0; k+=0.4){
    23. painter->drawLine(QLineF(left+i+2*j+k, rect().bottom(), left+i+2*j+k, rect().bottom()-2));
    24. }
    25. }
    26. }
    27. }
    28. }
    29. }
    30. };
    31.  
    32. class GraphicsView : public QGraphicsView {
    33. public:
    34. GraphicsView():QGraphicsView(){}
    35. protected:
    36. void wheelEvent(QWheelEvent *e){
    37. int delta = e->delta();
    38. if(delta>0) scale(1.2, 1.2);
    39. else if(delta<0) scale(1.0/1.2, 1.0/1.2);
    40. }
    41. };
    42.  
    43. int main(int argc, char **argv){
    44. QApplication app(argc,argv);
    45. GraphicsView view;
    46. view.setScene(new QGraphicsScene(0,0,600,400));
    47. ResItem *item = new ResItem;
    48. item->setRect(-50, -50, 300, 100);
    49. view.scene()->addItem(item);
    50. item->setPos(300,250);
    51. item->setFlag(QGraphicsItem::ItemIsMovable);
    52. view.show();
    53. return app.exec();
    54. }
    To copy to clipboard, switch view to plain text mode 

    Use the mouse wheel to see the effect.

  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Issues with the Graphics View Framework

    You are right about the device being painted on has a finite and fixed resolution, but you are wrong that the zoom should not improve the resolution.

    If you plot 1000 points in a small area, you see a cloud of a mess, if you plot the same amount of data in larger area, you can tell which point is which, and that is what the zoom should be. I think you have not been involved in many application development so you may not have understood what the end users really want.

    In your particular example, you made a very simple plot, so you only see a small side of the rule, but try to replace with the following codes, you should see the markers grow as you zoom in, and no matter how much you zoom, you can't tell that I am plotting 10 points.

    And When user zooms in, what users want to see is the data, not the huge text string that got blown out of the screen. So please provide an QPen::setCosmetic equivalent QFont.

    I have also looked into QGraphicsWidget, and it has no difference.

    As I said, the best example that the end users want are example shown in Qwt, try Qwt's realtime example. It is the one people are looking for. Unfortunately, Qwt doesn't have all we want...

    You guys spent a lot of effort already, with some improvement, I think Qt graphics can really become a power house.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class ResItem : public QGraphicsRectItem {
    4. public:
    5. ResItem() : QGraphicsRectItem(){}
    6.  
    7. void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ){
    8.  
    9. QPointF p1( 0, 10 );
    10. QPointF p2( 5, 10 );
    11. QPointF p3( 2, 8 );
    12. QPointF p4( 2, 12 );
    13. QPointF pp( 2, 0 );
    14. for ( int idx=0; idx<10; idx++ ) {
    15. painter->drawLine( p1, p2 );
    16. painter->drawLine( p3, p4 );
    17. p1 += pp;
    18. p2 += pp;
    19. p3 += pp;
    20. p4 += pp;
    21. }
    22.  
    23. }
    24. };
    25.  
    26. class GraphicsView : public QGraphicsView {
    27. public:
    28. GraphicsView():QGraphicsView(){}
    29. protected:
    30. void wheelEvent(QWheelEvent *e){
    31. int delta = e->delta();
    32. if(delta>0) scale(1.2, 1.2);
    33. else if(delta<0) scale(1.0/1.2, 1.0/1.2);
    34. }
    35. };
    36.  
    37. int main(int argc, char **argv){
    38. QApplication app(argc,argv);
    39. GraphicsView view;
    40. view.setScene(new QGraphicsScene(0,0,600,400));
    41. ResItem *item = new ResItem;
    42. item->setRect(-50, -50, 300, 100);
    43. view.scene()->addItem(item);
    44. item->setPos(300,250);
    45. item->setFlag(QGraphicsItem::ItemIsMovable);
    46. view.show();
    47. return app.exec();
    48. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Issues with the Graphics View Framework

    Quote Originally Posted by lni View Post
    You are right about the device being painted on has a finite and fixed resolution, but you are wrong that the zoom should not improve the resolution.
    It will not improve the resolution of the output device, it will improve resolution (number of details you can distinguish) of the scene. It is the resolution of the device that determines the number of details of the scene you can see - the better your eye sight the more details you will see in the same weather conditions.

    [quote[If you plot 1000 points in a small area, you see a cloud of a mess, if you plot the same amount of data in larger area, you can tell which point is which, and that is what the zoom should be.[/quote]
    And it is exactly the way it is.

    I think you have not been involved in many application development so you may not have understood what the end users really want.
    Right Let's make a poll and see what others think about graphics view zooming.

    In your particular example, you made a very simple plot, so you only see a small side of the rule, but try to replace with the following codes, you should see the markers grow as you zoom in, and no matter how much you zoom, you can't tell that I am plotting 10 points.
    Right... you can call QPainter::drawLine() as many times as you want and it won't draw a circle. Why? Because it's not supposed to... If you call drawEllipse() on the other hand, it will draw an ellipse. If your code is not correct, it won't do what you want it to.

    Actually I don't see your point. You are plotting lines and expect to see points? Would you care to explain that?

    And When user zooms in, what users want to see is the data, not the huge text string that got blown out of the screen. So please provide an QPen::setCosmetic equivalent QFont.
    Make it yourself, Qt is Open Source I understand there could be an option which you suggest available but I don't say the lack of it makes Graphics View work incorrectly. Especially that you can obtain the effect you want using ItemIgnoresTransformations. Even the docs say:

    This flag is useful for keeping text label items horizontal and unscaled, so they will still be readable if the view is transformed. When set, the item's view geometry and scene geometry will be maintained separately. You must call deviceTransform() to map coordinates and detect collisions in the view.
    I have also looked into QGraphicsWidget, and it has no difference.
    Why would you expect it behaved differently?

    As I said, the best example that the end users want are example shown in Qwt, try Qwt's realtime example. It is the one people are looking for. Unfortunately, Qwt doesn't have all we want...
    Qwt is for something more specific than Graphics View.

    You guys spent a lot of effort already, with some improvement, I think Qt graphics can really become a power house.
    It's not us It's Andreas Hanssen and his team mostly

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

    Default Re: Issues with the Graphics View Framework

    Here you go, another teaser...
    Attached Files Attached Files

  6. #6
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issues with the Graphics View Framework

    In terms of fonts and zooming, consider using the flag QGraphicsItem::ItemIgnoresTransformations. This tells the item not to inherit its parents transform. Thus you can zoom in on a item but the child text remains the same size. Also useful for rotating items without rotating the text. I've also seen it used to zoom in on line charts, but keep the markers the same size.

  7. #7
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Issues with the Graphics View Framework

    Quote Originally Posted by wysota View Post
    Here you go, another teaser...
    Thanks!

    But I just need to plot X/Y axis's label tick, such as 0, 5, 10, 15, 20.... creating QGraphicsItem for each tick is to much for such use.

    I need to plot a scene of very long section along vertical depth, from 0 to 100,000 meters with increment of 5 meters, I would have to create 20,000 such QGraphicsItem for the text. Performance would be very bad.

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

    Default Re: Issues with the Graphics View Framework

    Pefrormance would be fine as only those items that are visible on the screen are rendered. Increase the number of points in my example to 10k or so and zoom in. You can also increase performance by using QGLWidget as a viewport for your view. GraphicsView scales fine up to hundreds of thousands or even millions of items.

    If you want to avoid drawing many items, then implement a single item for all the ticks and use levelOfDetail to decide what to draw. As for your fonts issues, you can invert the transformation matrix of the item to get 1:1 mapping with the view so that fonts look small. Beware it probably won't look good on printers.

  9. #9
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Issues with the Graphics View Framework

    Is there a bug in 4.5.0 because QVBoxLayout::addWidget(QGraphivcsView*) crashes my application?
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. Qt Coordinate System and the Graphics View Framework
    By djurodrljaca in forum Qt Programming
    Replies: 14
    Last Post: 17th February 2012, 12:19
  2. Graphics View Panning ,zooming
    By linuxdev in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2008, 08:17
  3. Replies: 4
    Last Post: 5th August 2008, 20:55
  4. Graphics View Event Propagation
    By pherthyl in forum Qt Programming
    Replies: 10
    Last Post: 3rd July 2008, 11:39
  5. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 08:08

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.