Re: Line not being created
You must first draw it. Use draw() method
Re: Line not being created
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 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
Re: Line not being created
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
Code:
#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
Code:
#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
Code:
#include <QApplication>
#include "imagezoomer.h"
#include "ui_zoomsample.h"
int main(int argc, char **argv)
{
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
Code:
#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
Re: Line not being created
Hi..
I got the solution ... I was not the calling the canvas->resize() function...
Now it is executing pretty fine...
Kapil