PDA

View Full Version : Unable to resize a QCanvas.



yellowmat
21st June 2006, 10:07
Hi everybody !

I'm testing QCanvas and I have a problem with it, I'm not able to resize it ... or the results doesn't correspond to what I expected to.

So I have a main application that have for the moment a QCanvas and a QCanvasView as member. In the init slot I do this :


void CanvasMainWindow::init()
{
pCanvas = 0;
pCanvasView = 0;

/////////////////////////////////////
// Construction and initialisation of canvas object
//
pCanvas = new QCanvas(this, "myCanvas");
Q_ASSERT( pCanvas );
pCanvas->resize(800, 600);


/////////////////////////////////////
// Construction and initialisation of canvasview object
//
pCanvasView = new QCanvasView(this, "myCanvasView");
Q_ASSERT( pCanvasView );
pCanvasView->setCanvas(pCanvas);
}


It compiles but when I start the application it only shows me my window with the right size but it only contains a small scrolling area which, I suppose, must be my QCanvas view attached to my QCanvas.

Despite I called the resize method of QCanvas, it looks not to be applied because the view is very small ... maybe something like 80x20.

So what is the problem with my code ?

Thanks in advance.

yellowmat
21st June 2006, 10:15
I add the following line at the end of the init slot and my view fits to my main application :


setCentralWidget(pCanvasView);

jacek
21st June 2006, 13:52
Despite I called the resize method of QCanvas, it looks not to be applied because the view is very small ... maybe something like 80x20.

So what is the problem with my code ?
You have set the size of the canvas itself, but the view has its own size --- you must set it too (you do it just like with any other widget).