Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Digitising (GIS)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Digitising (GIS)

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PrathibaVishnu
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      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_OBJECT

      public:
      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();
      }
      @

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on last edited by
        #3

        Please add "[SOLVED]" left to the topic subject if your problem is solved. Thank!

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PrathibaVishnu
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Come on. You got really good help: ready made code for you to play with. You can't expect others on this forum to do your work for you of integrating that into your project. If you're looking for that kind of help, please go look for a consultant instead.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved