You Are Here:

Community: Wiki

This page was last modified on 31 October 2009, at 15:48.

Line drawing with mouse coordinate

From Forum Nokia Wiki



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

Overview

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.


Preconditions


Source Code

Source.h

#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

Source.cpp

#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);
 
}

ScreenShot

Image:EVE1.jpg

NOTE:MOVE YOUR MOUSE ARROUND THE WIDGET NOT ON THE WIDGET....

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fThemesE3aHomeE5fScreenX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ