| ID | ... | Creation date | 23 June 2009 |
| Platform | S60 3rd Edition FP2, S60 5th Edition | Tested on devices | S60 Emulator |
| Category | Qt for S60 | Subcategory | Application |
| Keywords (APIs, classes, methods, functions): QGraphicsScene,QGraphicsView |
This code will show you the line drawing in the QGraphicsScene by getting the end points of line with the help of mouseMove() Event.
When the mouse is moved on the widget at that time the mouse coordinates are catched and use to draw line from center to that specific coordinate.
#ifndef EVE1_H
#define EVE1_H
#include <QtGui/QWidget>
#include<QMouseEvent>
#include<QGraphicsLineItem>
#include<QGraphicsScene>
#include<QGraphicsView>
#include<QGraphicsItem>
#include<QHBoxLayout>
class EVE1 : public QWidget
{
Q_OBJECT
public:
EVE1(QWidget *parent = 0);
~EVE1();
private:
QHBoxLayout *lay;
QGraphicsScene *scene;
QGraphicsItem *item;
QGraphicsView *view;
private slots:
void mouseMoveEvent(QMouseEvent *);
};
#endif // EVE1_H
#include "eve1.h"
#include "ui_eve1.h"
EVE1::EVE1(QWidget *parent)
: QWidget(parent)
{
lay=new QHBoxLayout(this);
scene=new QGraphicsScene(this);
scene->setSceneRect(0,0,250,250);
view=new QGraphicsView(scene,this);
view->show();
setMouseTracking(1);//Enable Mouse tracking on widget.
lay->addWidget(view);
setLayout(lay);
}
EVE1::~EVE1()
{
// No need to delete any object that has got a parent which is properly deleted.
}
void EVE1::mouseMoveEvent(QMouseEvent *event)
{
int X=event->x();
int Y=event->y();
int Z=scene->height()/2;
int W=scene->width()/2;
scene->addLine(Z,W,X,Y);
}
NOTE:MOVE YOUR MOUSE ARROUND THE WIDGET NOT ON THE WIDGET....
No related wiki articles found