PDA

View Full Version : change bounding of QGraphicsScene



danics
14th July 2012, 21:27
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.

wysota
15th July 2012, 10:15
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.

danics
15th July 2012, 16:31
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

wysota
15th July 2012, 17:06
You can enable clipping for the view to only allow drawing on certain area. However that will have impact on performance.

danics
15th July 2012, 20:53
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?

wysota
16th July 2012, 02:27
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.

danics
16th July 2012, 07:21
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.

wysota
16th July 2012, 11:03
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.

danics
16th July 2012, 17:21
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?:confused:
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.

wysota
16th July 2012, 17:24
my goals?:confused:
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.

danics
17th July 2012, 06:31
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?

wysota
17th July 2012, 10:33
drawBackground() has nothing to do with items. You are supposed to paint directly on a given painter.

danics
17th July 2012, 11:36
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

aamer4yu
17th July 2012, 12:07
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.

wysota
17th July 2012, 12:10
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.

danics
18th July 2012, 12:45
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


void RadarCircle::paintEvent(QPaintEvent *){
if(backInvalidate){
backImage = QImage(QSize(width(), height()), QImage::Format_ARGB32_Premultiplied);
backImage.fill(qRgba(0,0,0,0));

QPainter imagePainter(&backImage);
imagePainter.setRenderHint(QPainter::Antialiasing) ;
createBackground(&imagePainter);
backInvalidate = false;
}

if(foreInvalidate){
foregroundImage = QImage(QSize(width(), height()), QImage::Format_ARGB32_Premultiplied);
foregroundImage.fill(qRgba(0,0,0,0));

QPainter imagePainter(&foregroundImage);
imagePainter.setRenderHint(QPainter::Antialiasing) ;
createForeground(&imagePainter);
foreinvalidate = false;
}

QPainter* mainPainter = new QPainter(this);
mainPainter->setRenderHint(QPainter::Antialiasing);
mainPainter->resetTransform();
mainPainter->drawImage(0, 0, foregroundImage);
mainPainter->drawImage(0, 0, backImage);
paintTargets(mainPainter);
drawHand(mainPainter);

delete mainPainter;
}

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

aamer4yu
18th July 2012, 13:00
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.

wysota
18th July 2012, 17:02
What's the superclass of RadarCircle?

danics
19th July 2012, 17:54
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

wysota
19th July 2012, 21:20
base class is QWidget

And how is that related to Graphics View?

danics
19th July 2012, 21:24
i dont use GraphicsView in this scenario, i load my images when i needed them

wysota
20th July 2012, 00:09
i dont use GraphicsView in this scenario
Why then your thread title says "QGraphicsScene"?


i load my images when i needed them
What does it have to do with using Graphics View?