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. Showing of drawn rectangles
Forum Updated to NodeBB v4.3 + New Features

Showing of drawn rectangles

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.0k 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.
  • S Offline
    S Offline
    szmitek
    wrote on last edited by
    #1

    How to make showing of rectangles while they are drawing in Qt?

    My scene of the drawing is as follows:
    @#include <QtGui/QMainWindow>
    #include "ui_rectangleview.h"
    #include "rectangleview.h"
    class Scene : public QGraphicsScene
    {
    private:
    int X, Y;
    QGraphicsView *Parent;
    public:

    Scene(QGraphicsView *parent) : QGraphicsScene(parent)
    {
    Parent = parent;
    addLine(-250,0,250,0,QPen(Qt::red));
    addLine(0,-230,0,250,QPen(Qt::red));
    }
    void mousePressEvent(QGraphicsSceneMouseEvent *e)
    {
    X = e->scenePos().x();
    Y = e->scenePos().y();
    }
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
    {
    QGraphicsItem *item = 0;

    QRectF r(X, Y, e->scenePos().x()-X, e->scenePos().y()-Y);
    addRect(r, QPen(Qt::black),Qt::NoBrush);

      //Parent->mapToScene(e->pos());
      //Parent->setFlag(QGraphicsItem::ItemIsMovable);
    

    }
    };@

    Rectangles are drawn when you release the mouse button. I want rectangles to be shown when moving the mouse. Please help.

    Kamil Szmit
    http://szmit.yoyo.pl

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Peppy
      wrote on last edited by
      #2

      QGraphicsScene::mouseMoveEvent() ??? But I've never do this...Look at classes: "QGraphicsWidget":http://doc.trolltech.com/4.7-snapshot/qgraphicswidget.html, "QGraphicsItem":http://doc.trolltech.com/4.7-snapshot/qgraphicsitem.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        szmitek
        wrote on last edited by
        #3

        What shoud I put in QGraphicsScene::mouseMoveEvent() function (in order that rectangle is drawn temporary, not permanently added to scene)?

        Kamil Szmit
        http://szmit.yoyo.pl

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

          bq. Rectangles are drawn when you release the mouse button. I want rectangles to be shown when moving the mouse.

          Your last sentence is quite unlogical...

          If you want to see anything, you have to draw it. If you want to draw, when you move your mouse, use that event as I mentioned above. On painting it uses paintEvent...but...

          You are not allowed to draw in QGraphicsScene, because it's just map (what come where, and what will stay at top, and so on...), it's not a widget, you have to draw in @void QGraphicsItem::paint()@ or in @QGraphicsView::paintEvent(...)@ , which gives painter to all used objects/items (QGraphicsItem through paint() method)

          My advice is: You shouldn't work in QGraphicsScene but in QGraphicsView, it'll be better...And even better will be, to work in QGraphicsItem...

          Best wishes...

          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