PDA

View Full Version : Qpainter, drawPolygon, fillpath, bouding rect ....



Speerfish
13th February 2014, 13:06
frameX::frameX(QGraphicsItem *parent)
: position(parent)
{
setAcceptHoverEvents(true);
this->StatusState=Status::deselected;
this->rotCenter=0;
this->fillQColor= (Qt::transparent);
this->setFrameEnumXXType(type::Xarea);
this->wide =128;
this->high =128;
}

QRectF frameX::boundingRect() const
{
return QRectF(0,0,this->wide,this->high);
}

QPainterPath frameX::shape() const
{
QPainterPath path;
path.addPolygon(polygonType);
return path;
}

void frameX::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QPen pen;
QBrush brush;
QPainterPath painterPath;
pen.setWidth(4);
pen.setColor(Qt::black);
pen.setJoinStyle(Qt::RoundJoin);
brush.setColor(this->fillQColor);
brush.setStyle(Qt::SolidPattern);
painterPath.addPolygon(this->polygonType);
painter->setPen(pen);
painter->drawPolygon(this->polygonType);
painter->fillPath(painterPath,brush);
}

void frameX::mousePressEvent(QGraphicsSceneMouseEvent *event){
if(event->button() == Qt::RightButton){
qDebug()<< "right button";
}
else if(event->button() == Qt::LeftButton){
//qDebug()<< "right button";
if (getFrameStatus()== Status::selected){
setFrameStatus(Status::deselected);
}
else{
setFrameStatus(Status::selected);
}
}
else{
qDebug()<< "wheel button";
}
}

void frameX::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
/**hover enter event, place text here*/
// setToolTip(QString(QObject::tr(("example"))));
}

void frameX::setFrame(qreal xPos, qreal yPos, qreal rotCenter, type::frames frameType)
{
setFrameEnumXXType(frameType);
this->rotCenter=rotCenter;
this->xPos=xPos;
this->yPos=yPos;
this->centerX = this->wide/2;
this->centerY = this->high/2;
setPos(this->xPos-(this->centerX),this->yPos-(this->centerY));
this->transform.translate(this->centerX,this->centerY);
this->transform.rotate(this->rotCenter);
this->transform.translate(-(this->centerX),-(this->centerY));
setTransform(this->transform);
}

void frameX::setFrameStatus(Status::frameState myFrameState)
{
switch(myFrameState)
{
case Status::selected:
this->StatusState = Status::selected;
qDebug() << "umbrella selected";
this->fillQColor = (QColor(0,0,255,70));
break;
case Status::approved:
this->StatusState = Status::approved;
qDebug() << "selection approved";
this->fillQColor = (QColor(0,255,0,70));
break;
case Status::deselected:
this->StatusState = Status::deselected;
qDebug() << "umbrella deselected";
this->fillQColor = (Qt::transparent);
break;
default:
qDebug() << "requested fill color" << myFrameState << "not avaliable";
break;
}
update();
}

int frameX::getFrameStatus() const
{
return this->StatusState;
}


if the inside of the polyon is clicked it turns blue otherwise transparent.
10043
But everytime if i just move over with the cursor, the painter paints the bounding rect
white -> the green outline which is painted in a other class is overpainted.
10044
What am i doing wrong......

Speerfish
14th April 2014, 09:54
found the problem, actually it is not a problem, just the way relalizes what has or will be updated.
Changed the properties that one change in the child object, letÅ› all other itmes per default also be redrawn....