PDA

View Full Version : QCanvas Examples



Kapil
20th March 2006, 09:16
Hi,

Can anyone please tell me how do we use QCanvas inplace of QWidget or QMainWindow and suggest me few programming examples on how to use QCanvas.

thanking you,
Kapil

wysota
21st March 2006, 11:44
You don't use QCanvas "in place" of QWidget (or any of its descendants). QCanvas is a mechanism to operate on double buffered objects which get displayed using QCanvasView. What kind of examples do you want? You have some examples in Qt docs. Aren't they enough?

Kapil
23rd March 2006, 12:02
You don't use QCanvas "in place" of QWidget (or any of its descendants). QCanvas is a mechanism to operate on double buffered objects which get displayed using QCanvasView. What kind of examples do you want? You have some examples in Qt docs. Aren't they enough?

Hi,

What are double buffered objects???? i couldn't understand that :(

I want Image Managing and Tiles Creation example related to QCanvas.. There are quite a lot of examples there and are real good ones but none use QCanvas and are not even a bit close to the examples i want...

thanking you,

Kapil

wysota
23rd March 2006, 12:18
The first question is -- why do you want to use QCanvas at all?
The second one is -- why do you want to use QCanvas if you don't even know what it does?

Kapil
23rd March 2006, 12:51
hi..

I want to use QCanvas because ->
I have a BIG Design file from which a BIG Design Image with rectangles, lines and circles is created dynamically... Now when i create it and show it, it takes lots of time..
I want my execution time to be very less.. So I thought of generating only that part of the image which can be seen on the screen... when the user moves the scrollbar top-down or left-right, that part of the image is created that comes in display...All this happens dynamically with the Scroll Bar events... Now i had put up a query for the same and got the reply to use QCanvas which handles the things in a similar manner..
I created few applications using QCanvas and QCanvasView and they got executed well..Now there is a function called setTiles() which helps me show only those tiles which are currently in display and the moment the scroll bar movement happens, it captures those events and paints the new tiles.. Thus i have divided my design into smaller number of tiles and want to execute it in the same way... This is what i want to do....
But then am not getting enough examples which could tell me dynamic creation of that part of image which would be in display only...
I hope i have been able to convey you what i want....
Now if there is some other way also to solve the problem then plz tell me, i would be thabkful to you 'coz its been just 1 month since i have started using it... I dont know how to use it but why not trying it out and knowing it..
The problems is similar to the query i had put up in the Viewport thread...

Thanking you,
Kapil

wysota
23rd March 2006, 13:02
With QCanvas you shouldn't generate only "a part" of display. QCanvas approach is to be used when you have persistent objects which are generated once and then redrawn when needed by QCanvas mechanism. If an object doesn't fit on the viewport, it won't be drawn. Everything is double buffered, meaning that the actual drawing takes place of screen and is then just rendered on the widget (and only those parts which are considered "dirty") which makes drawing faster and without flicker. It also allows easy access to a particular object in case you want to implement selecting or moving them.

When using QCanvas you should focus on each particular object separately -- don't "look" at all of them at once. Based on this, there is no "part which is visible". There is no dynamic creation of objects -- this breaks down everything that makes QCanvas fast. Please remember it is not a general use drawing canvas. There is the QPainter approach for that.

jacek
23rd March 2006, 13:12
But then am not getting enough examples which could tell me dynamic creation of that part of image which would be in display only...
You shouldn't need this, if your whole design can be represented as QCanvasItems which fit in memory.

If you can't fit your design in memory, then you should rather subclass QWidget and implement such functionality yourself. For example using spatial index like UB-tree, to find objects that fit in areas that should be redrawn.