hello,
i wrote a class that handles simple drawing actions
here is the header file
#ifndef PARENT_LINE
#define PARENT_LINE
#include <QFrame>
#include <QPainter>
#include <QMouseEvent>
class parentLine
: public QFrame{
Q_OBJECT
public:
parentLine
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~parentLine();
protected:
bool isDrawing;
};
#endif
#ifndef PARENT_LINE
#define PARENT_LINE
#include <QFrame>
#include <QPainter>
#include <QMouseEvent>
class parentLine : public QFrame
{
Q_OBJECT
public:
parentLine(QWidget *parent = 0, Qt::WFlags flags = 0);
~parentLine();
protected:
QPoint * tmpFirstPoint;
bool isDrawing;
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
};
#endif
To copy to clipboard, switch view to plain text mode
and cpp
#include "parentLine.h"
parentLine
::parentLine(QWidget *parent, Qt
::WFlags flags
){
setMouseTracking(true);
isDrawing = false;
}
parentLine::~parentLine(){}
if(isDrawing){
int x1 = tmpFirstPoint->x();
int y1 = tmpFirstPoint->y();
int x2 = event->pos().x();
int y2 = event->pos().y();
painter.drawLine(x1,y1,x2+5,y2+5);
isDrawing = true;
}
}
{
isDrawing = true;
tmpFirstPoint
= new QPoint(event
->pos
().
x(),event
->pos
().
y());
}
{
isDrawing = false;
tmpFirstPoint = 0;
}
#include "parentLine.h"
parentLine::parentLine(QWidget *parent, Qt::WFlags flags)
: QFrame(parent, flags)
{
setMouseTracking(true);
isDrawing = false;
QPoint *tmpFirstPoint = new QPoint(0,0);
}
parentLine::~parentLine(){}
void parentLine::mouseMoveEvent(QMouseEvent *event){
if(isDrawing){
QPainter painter(this);
int x1 = tmpFirstPoint->x();
int y1 = tmpFirstPoint->y();
int x2 = event->pos().x();
int y2 = event->pos().y();
painter.drawLine(x1,y1,x2+5,y2+5);
isDrawing = true;
}
}
void parentLine::mousePressEvent(QMouseEvent *event)
{
isDrawing = true;
tmpFirstPoint = new QPoint(event->pos().x(),event->pos().y());
}
void parentLine::mouseReleaseEvent(QMouseEvent *event)
{
isDrawing = false;
tmpFirstPoint = 0;
}
To copy to clipboard, switch view to plain text mode
when i try to promote this class to any widget the designer warns as "parentLine cannot be used as the class of the promoted widget, as a class of that name already exists and extends QWidget"
what i'm doing wrong? 
promote-problem.jpg
Bookmarks