PDA

View Full Version : Elements out of Range!!



Kapil
31st March 2006, 06:52
Hi...

The objects that i have created are going out of the range of the canvas...
My canvas size is (400,400) -> visible to the user...
i have set the CanvasView to (1000,1000)..
Now when i create objects on canvas, only those which fit on the canvas ie whose x,y coordinates are withing canvas zise ie (400,400) are created and rest all are not...
I cannot increase the size of the Canvas...
How do i create beyond the Canvas Size and view them with the help of Scroll View..
Is it possible to create items till the size (1000,1000) and let only (400,400) be visible on the frame...

Thanking you,
Kapil

zlatko
31st March 2006, 08:37
Try use resizeContents ( int w, int h ) for canvas view

Kapil
31st March 2006, 08:50
Try use resizeContents ( int w, int h ) for canvas view

Hi..

i used that.. But then it adds a Scroll Bar to the Canvas but does not permit me to draw the elements...

Isn't there a way with which i am able to create a Canvas of large size but only smaller portion of it is shown and rest can be seen with the help of moving scrollbars..

resizeContents(x,y) is not doing the trick.. I checked with it..

Kapil

zlatko
31st March 2006, 09:03
Then post actual part of your code

Kapil
31st March 2006, 09:39
Then post actual part of your code

The code is:

ImageZoomer.cppThis class sets the Frame wherein i would place the Canvas:


#include "imagezoomer.h"
#include <QtGui>
#include <qdir.h>
#include <QColor>

ImageZoomer::ImageZoomer(Ui::MainWindow *_mwin, Q3Canvas *pCanvas): mwin(_mwin),m_pCanvas(pCanvas)
{

frame = new QFrame(mwin->centralwidget);
frame->setGeometry(QRect(60, 70, 591, 571));
frame->setFrameShape(QFrame::StyledPanel);
frame->setFrameShadow(QFrame::Plain);

canmouse = new CanvasMouse(m_pCanvas,frame); //Sends the canvas obj and frame obj to CanvasMouse
}
ImageZoomer::~ImageZoomer()
{
}


CanvasMouse.cpp: This class would create the canvas, set its size and set the CanvasView for it..



#include "canvasmouse.h"

CanvasMouse::CanvasMouse(Q3Canvas *pCanvas, QFrame *frame): Q3CanvasView(frame)
{
m_pCanvas = pCanvas;
Q3CanvasView::setCanvas(m_pCanvas);
m_pCanvas->setBackgroundColor(Qt::white);
m_pCanvas->resize(400, 400);
resizeContents(1000,1000);

imgdraw = new ImageDraw(m_pCanvas);

setDraw = false;
startDraw = false;
}

CanvasMouse::~CanvasMouse()
{
}


ImageDraw.cpp: This class would actually draw the elements on the canvas and then display them... Here is the problem.. only 4 rectangles are being created as they fall out of the range of the Canvas...



#include "imagedraw.h"
#include <Q3ValueList>

ImageDraw::ImageDraw(Q3Canvas *pCanvas): m_pCanvas(pCanvas)
{
drawLine();
drawRectangle();
}
ImageDraw::~ImageDraw()
{
}
void ImageDraw::drawLine()
{
int i;
int xxPoint = 2,xyPoint = 2,yxPoint = 202,yyPoint = 2;
lineNum = 20;
m_pCanvasLine = new Q3CanvasLine*[lineNum];
for(i=0;i<lineNum;i++)
{
xyPoint = (i+1)*4;
yyPoint = xyPoint;
m_pCanvasLine[i] = new Q3CanvasLine(m_pCanvas);
m_pCanvasLine[i]->setPoints(xxPoint,xyPoint,yxPoint,yyPoint);
m_pCanvasLine[i]->show();

}

for(i=0;i<lineNum;i++)
lineList.append(m_pCanvasLine[i]);

}

void ImageDraw::drawRectangle()
{
int xPoint = 4, yPoint = 100;
int height = 50, width = 80;
int i;
recNum = 10;
m_pCanvasRectangle = new Q3CanvasRectangle*[recNum];
for(i=0;i<recNum;i++)
{
m_pCanvasRectangle[i] = new Q3CanvasRectangle(xPoint, yPoint, width, height, m_pCanvas);
m_pCanvasRectangle[i]->show();
yPoint += 75;
}
for(i=0;i<recNum;i++)
rectList.append(m_pCanvasRectangle[i]);

}



Thanks

Kapil

Kapil
1st April 2006, 05:55
Hi..

I checked quite a few docs and examples but none of them are able to give me a clue regarding my doubt....
what can be the approach to solve it out...

KApil

wysota
2nd April 2006, 16:08
You have some strange problem. Resizing the canvas makes the canvas bigger. Which part of it is visible has nothing to do with the canvas itself, only with the canvasview size and its world matrix. What exactly do you want to achieve and why?

Kapil
3rd April 2006, 05:01
You have some strange problem. Resizing the canvas makes the canvas bigger. Which part of it is visible has nothing to do with the canvas itself, only with the canvasview size and its world matrix. What exactly do you want to achieve and why?


Hi...

Thats my problem.. resizing it is making it bigger than the size i need... I just need 400 X 400 to be seen in the window and the actual canvas to be 1000 X 1000...

Using canvasview's resizeContents() method, i culdnt get the soln... The problem with it is that it does not reduce the canvas size... if the view's size is greater than the canvas size then the scrollbars are added...

Now when i keep view bigger and canvas smaller then the elements are just created on the canvas's size and thus not all are created... the moment i increase it, it goes out of the window...

thats the problem..

wysota
3rd April 2006, 10:12
QCanvas *c;
QCanvasView *cv;
//...

c->resize(1000,1000);
cv->setFixedSize(400,400);

This will display a bit less than 400x400 (because of the scrollbars).

Kapil
3rd April 2006, 10:28
Hi wysota..

Thanks a lot for your help..

Its working out now...

Kapil