@Painting

Почему не происходит рисование?

Здравствуйте.
Есть графическая сцена , в ней должно происходить рисование мышью.
Но приложение запускается, а линия не рисуется. Компилятор выдает только пару предупреждений.
В чем подвох?
#pragma once
#include <QWidget>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QRectF>
#include <QPushButton>
#include <QGraphicsItem>
#include <QLineEdit>
#include <QMouseEvent>

class Paint : public QWidget
{
    Q_OBJECT
public:
    Paint(QWidget *parent = 0);
    QGraphicsScene *scene;
    QGraphicsView *view;

    QPushButton *btn;

private:
   QPointF  previousPoint;
   void mousePressEvent(QGraphicsSceneMouseEvent *e);
   void mouseMoveEvent(QGraphicsSceneMouseEvent *e);
};

#include "paint.h"
#include
#include
#include
#include

Paint::Paint(QWidget *parent):QWidget(parent)
{
scene = new QGraphicsScene(QRectF(10,10,1000,1000));

view = new QGraphicsView(scene, this);

view->show();

btn = new QPushButton("Draw!", this);
btn -> setGeometry(1020, 10, 70, 30);

}
void Paint::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
QGraphicsEllipseItem *p = scene->addEllipse(e->scenePos().x() - 5,e->scenePos().y() - 5,
10,
10,
QPen(Qt::NoPen),
QBrush(Qt::red));
previousPoint = e->scenePos();
}
void Paint::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
{

QGraphicsLineItem *f = scene->addLine(previousPoint.x(),
previousPoint.y(),
e->scenePos().x(),
e->scenePos().y(),
QPen(Qt::red,10,Qt::SolidLine,Qt::RoundCap));

previousPoint = e->scenePos();
}

<code lang="cpp">
QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    paint.cpp

HEADERS += \
    paint.h

FORMS +=

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

</code>

Заранее спасибо...
  • Вопрос задан
  • 94 просмотра
Пригласить эксперта
Ответы на вопрос 1
Потому что функции mousePressEvent и mouseMoveEvent никем и никогда не вызываются.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы