[SOLVED] Digitising (GIS)
-
Hi,
I'am new to Qt. The task may be simple but am not getting it. Can any one help me to develop points on MousePressEvent and to develop a straight line between two consecutive points.
-
Here you go:
widget.h:
@
#ifndef WIDGET_H
#define WIDGET_H#include <QtGui/QWidget>
#include <QPaintEvent>
#include <QMouseEvent>
#include <QLine>
#include <QPoint>
#include <QVector>class Widget : public QWidget
{
Q_OBJECTpublic:
Widget(QWidget *parent = 0);private:
QVector<QLine> lines;
QPoint last;protected:
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *);
};#endif // WIDGET_H
@widget.cpp:
@
#include "widget.h"
#include <QPainter>Widget::Widget(QWidget *parent):QWidget(parent)
{
this->last = QPoint(-1,-1);
}void Widget::paintEvent(QPaintEvent * e)
{
QPainter painter(this);
painter.fillRect(this->rect(), Qt::white);
painter.setPen(Qt::black);
if(this->lines.count() == 0)return;painter.drawLines(this->lines);
}
void Widget::mousePressEvent(QMouseEvent * e)
{
if(this->last.x() < 0 && this->last.y() < 0)
{
this->lines << QLine(e->pos(), e->pos());
}
else this->lines << QLine(this->last, e->pos());
this->last = e->pos();
this->update();
}
@ -
Please add "[SOLVED]" left to the topic subject if your problem is solved. Thank!
-
The code was really helpful. Is there any possibility to integrate the code mentioned in the link http://www.dazzle.plus.com/linux/QtCreator/part13.htm with the above mentioned code?
-