Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: change bounding of QGraphicsScene

  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default change bounding of QGraphicsScene

    Hi everyone i am newbie in qt programming, i want to change boundary of QGraphicsView or QGraphicsScene from a rectangle to circle, how can i do that?
    i want to create a UI like radar system. main Circle have my svg map and can zoom and pan without any scrollbar and some buttons out of this circle, i think of create a QPixmap and render it frequently and change createbackground() method of QGraphicsScene but i dont know how to implement zooming and padding in this solution.

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

    Default Re: change bounding of QGraphicsScene

    The boundary has to be a rectangle but nothing prevents you from placing a circular item in it and using just that area. If you want to get rid of the background around it then it is also possible, just set the frame of the view to NoFrame and change the palette of the view to make its Base component be either transparent or match the value of the Window component.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    danics (15th July 2012)

  4. #3
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    thanks for your reply,
    but how can i force QGraphicsScene to show only middle of circle and zoom in and out or panning only my qgraphicssvgitem, whats the best solution? for now i using a custom widget and mask circle area on it and add a qgraphicsview to this widget but this solution isn't good for me, so i googled of any other solution and masking on qgraphicsscene or qgraphicsview itself but without any success, if you explain more your suggestion for me i will thank of you

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

    Default Re: change bounding of QGraphicsScene

    You can enable clipping for the view to only allow drawing on certain area. However that will have impact on performance.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    danics (15th July 2012)

  7. #5
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    Quote Originally Posted by wysota View Post
    You can enable clipping for the view to only allow drawing on certain area. However that will have impact on performance.
    its not so much good for me, because my svg file is really big so i think i must draw all of my items in a image and paint that and then every-time i m need to scale my map change whole background image, but QGraphicsScene havent paintevent and i dont know when drawbackground() of this class is calling and how to work,
    another problem for me is some graphical widget that i dont need add their to qgraphicsscene( outside of this circle only added to Qgraphicsview)
    can i change paintevent of qgraphicsview for rendering my scene only and dont repaint these widgets?
    or i must create whole of my radar as a QgraphicsItem in this case how can i just repaint this item in whole scene and implement scaling for svg map?

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

    Default Re: change bounding of QGraphicsScene

    Maybe you should start from the beginning and tell us what exactly you are trying to do. I mean, something more detailed than that you're drawing a radar screen.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #7
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    i say you, you imagine you have a svg map like worldmap that you want add that in the center of some circles like radar, you have some target added in this map and you can select or move them and some button outside of this circle for changing zooming and panning and adding target to this map.

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

    Default Re: change bounding of QGraphicsScene

    Quote Originally Posted by danics View Post
    i say you, you imagine you have a svg map like worldmap that you want add that in the center of some circles like radar, you have some target added in this map and you can select or move them and some button outside of this circle for changing zooming and panning and adding target to this map.
    Sorry, this description is too vague to make out anything of it. I'm asking about your goals, not methods of achieving them.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    danics (16th July 2012)

  12. #9
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    Quote Originally Posted by wysota View Post
    Sorry, this description is too vague to make out anything of it. I'm asking about your goals, not methods of achieving them.
    my goals?
    so, loading a large svg file and creating some special map viewer for this file,
    for not confusing anyone else i ask another questions and myself decide how implement that,
    -how can i draw a svg file in background of a QGraphicsScene that cover whole scene?
    -- when scaling a scene my background must scale too?

    tnx for your attention again.

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

    Default Re: change bounding of QGraphicsScene

    Quote Originally Posted by danics View Post
    my goals?
    so, loading a large svg file and creating some special map viewer for this file,
    We won't make progress this way, you know...

    But let's have it your way...

    -how can i draw a svg file in background of a QGraphicsScene that cover whole scene?
    For example using QGraphicsScene::drawBackground()
    -- when scaling a scene my background must scale too?
    It can, it doesn't have to.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #11
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    but when i use paint method of QGraphicsSvgItem in drawpackground function its size isnt set with the size of scene how can i do this?

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

    Default Re: change bounding of QGraphicsScene

    drawBackground() has nothing to do with items. You are supposed to paint directly on a given painter.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #13
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    if i want draw svg file like raster files so why i must use svg? any other solution for changing scale and full view of a svg item in scene, and then clipping a rectangle of that

  17. #14
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    I dont think QGraphicsscene will be a good choice for you. You will need to re-draw the SVG at different scales...
    so a simple paint method will do.
    QGraphicsScene will help you only if you opt for opengl.

  18. The following user says thank you to aamer4yu for this useful post:

    danics (18th July 2012)

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

    Default Re: change bounding of QGraphicsScene

    Quote Originally Posted by danics View Post
    if i want draw svg file like raster files so why i must use svg?
    You don't have to use SVG. Besides I have no idea what does it have to do with this situation.

    any other solution for changing scale and full view of a svg item in scene, and then clipping a rectangle of that
    There are lots of possible solutions but they all involve rasterizing the SVG at some point. Unfortunately physical devices have limited resolution so at some point they need to have a raster rather than mathematical representation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. The following user says thank you to wysota for this useful post:

    danics (18th July 2012)

  21. #16
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    i m handling this situation with using of create different tile in different zoom mode and loading them in application, but i have a periodic repaint in my widget and this function get so many cpu usage this is my paint

    Qt Code:
    1. void RadarCircle::paintEvent(QPaintEvent *){
    2. if(backInvalidate){
    3. backImage = QImage(QSize(width(), height()), QImage::Format_ARGB32_Premultiplied);
    4. backImage.fill(qRgba(0,0,0,0));
    5.  
    6. QPainter imagePainter(&backImage);
    7. imagePainter.setRenderHint(QPainter::Antialiasing);
    8. createBackground(&imagePainter);
    9. backInvalidate = false;
    10. }
    11.  
    12. if(foreInvalidate){
    13. foregroundImage = QImage(QSize(width(), height()), QImage::Format_ARGB32_Premultiplied);
    14. foregroundImage.fill(qRgba(0,0,0,0));
    15.  
    16. QPainter imagePainter(&foregroundImage);
    17. imagePainter.setRenderHint(QPainter::Antialiasing);
    18. createForeground(&imagePainter);
    19. foreinvalidate = false;
    20. }
    21.  
    22. QPainter* mainPainter = new QPainter(this);
    23. mainPainter->setRenderHint(QPainter::Antialiasing);
    24. mainPainter->resetTransform();
    25. mainPainter->drawImage(0, 0, foregroundImage);
    26. mainPainter->drawImage(0, 0, backImage);
    27. paintTargets(mainPainter);
    28. drawHand(mainPainter);
    29.  
    30. delete mainPainter;
    31. }
    To copy to clipboard, switch view to plain text mode 

    how can i painting of my background and foreground only once?
    speed of my program in current coding is so slow

  22. #17
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    The paintEvent will always get called when it needs an update.
    Your paint event seems somewhat heavy. Try using a back and front image separately and simply draw them in paintEvent. Do not create them in paint Event.

    You will need to simply update your member variable images from a function. This way the paintEvent will only paint, not create images.

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

    Default Re: change bounding of QGraphicsScene

    What's the superclass of RadarCircle?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  24. #19
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change bounding of QGraphicsScene

    The paintEvent will always get called when it needs an update.
    Your paint event seems somewhat heavy. Try using a back and front image separately and simply draw them in paintEvent. Do not create them in paint Event.

    You will need to simply update your member variable images from a function. This way the paintEvent will only paint, not create images.
    if you see, i only created main two images when i change my background or foreground, so this event only paint drawitems method and drawhand in every 600 msec, however the first method only paint 2 circles and anotherone draw a clock hand animation,

    What's the superclass of RadarCircle?
    base class is QWidget
    Last edited by danics; 19th July 2012 at 20:33.

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

    Default Re: change bounding of QGraphicsScene

    Quote Originally Posted by danics View Post
    base class is QWidget
    And how is that related to Graphics View?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 1st October 2011, 10:11
  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: 2
    Last Post: 29th March 2010, 13:34
  4. Getting the bounding rectangle
    By ioannis in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2009, 01:41
  5. Replies: 4
    Last Post: 16th March 2009, 10:08

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.