PDA

View Full Version : Error when promoting a custom widget



engin
15th December 2006, 16:49
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:
QPoint * tmpFirstPoint;
bool isDrawing;

void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
};
#endif



and cpp


#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;
}


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? :eek:

751

jpn
15th December 2006, 17:00
Sounds like you first attempted to promote a plain QWidget to "parentLine" and now when trying to fix the situation as the correct base class is QFrame, Designer thinks that this is something inappropriate. I'm not sure if there is any other way around than restarting the Designer...