PDA

View Full Version : Line not being created



Kapil
29th March 2006, 12:52
Hi...

I am trying to create a line on canvas but it is not being displayed.. i dont understand why it is not getting created... i had created applications using the same idea and they were being created... here it is not the case.. Am i missing something...



void ImageDraw::drawLine(QPoint point1, QPoint point2)
{
int xxPoint,xyPoint,yxPoint,yyPoint;
m_pCanvasLine = new Q3CanvasLine(m_pCanvas);
xxPoint = point1.x();
xyPoint = point1.y();
yxPoint = point2.x();
yyPoint = point2.y();
m_pCanvasLine->setPoints(xxPoint,xyPoint,yxPoint,yyPoint);
m_pCanvasLine->show();
resizeContents(400,400);
}


here m_pCanvas is a Canvas Object...

Thank you

Kapil

zlatko
29th March 2006, 13:04
You must first draw it. Use draw() method

Kapil
30th March 2006, 04:57
Hi...

draw() methos uses QPainter object but i have to create the line on the canvas...

I went thru the document of QCanvasLine and also the example canvas example (http://doc.trolltech.com/3.3/canvas-example.html#x2922) on it...

It also does not use the draw() method..

Also i created a simple independent application wherein i just create a canvas and draw a line and it is being created.. its just here where its causing the problem and am not able to make it out why....

Thanks..

Kapil

Kapil
30th March 2006, 06:12
Hi..

I deleted all my code and tried again but still its not happening.. i have no clue what can be the reason for non-creation of a line on the canvas... I am putting on the code.. Please help me to sort out the error...

canvasmouse.h


#ifndef CANVASMOUSE_H
#define CANVASMOUSE_H

#include "ui_zoomsample.h"
#include <Q3CanvasView>
#include <Q3Canvas>
#include <Qt>
#include <QtGui>
#include <Q3CanvasLine>

class CanvasMouse: public Q3CanvasView
{
Q_OBJECT

public:
CanvasMouse(Q3Canvas *pCanvas,QFrame *frame);
~CanvasMouse();

private:

void drawLine();
Q3Canvas *m_pCanvas;
Q3CanvasLine *m_pCanvasLine;
};

#endif



canvasmouse.cpp



#include "canvasmouse.h"
CanvasMouse::CanvasMouse(Q3Canvas *pCanvas, QFrame *frame): Q3CanvasView(frame)
{
m_pCanvas = pCanvas;
Q3CanvasView::setCanvas(m_pCanvas);
m_pCanvas->setBackgroundColor(Qt::white);
Q3CanvasView::resize(400, 400);
drawLine();
}
CanvasMouse::~CanvasMouse()
{
}
void CanvasMouse::drawLine()
{
m_pCanvasLine = new Q3CanvasLine(m_pCanvas);
m_pCanvasLine->setPoints(10,10,100,10);
m_pCanvasLine->show();
resizeContents(400,400);
}



main.cpp


#include <QApplication>
#include "imagezoomer.h"
#include "ui_zoomsample.h"

int main(int argc, char **argv)
{
QApplication app(argc,argv);
QMainWindow *form = new QMainWindow;

Ui::MainWindow *ui;
ui = new Ui::MainWindow();
ui->setupUi(form);
Q3Canvas *pCanvas = new Q3Canvas;
ImageZoomer imgzoom(ui,pCanvas);
form->show();
return app.exec();
}


imagezoomer.h


#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);
}
ImageZoomer::~ImageZoomer()
{
}


There is no compilation error.. It has to be somewhere logical... and i am not able to catch it.. Please help me in finding it out..

Thanking you...

Kapil

Kapil
30th March 2006, 06:49
Hi..

I got the solution ... I was not the calling the canvas->resize() function...
Now it is executing pretty fine...

Kapil