#include "item.h"
Item::Item()
{
hover = false;
setAcceptHoverEvents(true);
}
QRectF Item
::boundingRect() const {
qreal extra = (pen().width() + 20) / 2.0;
return QRectF(path
().
boundingRect()).
normalized().
adjusted(-extra,
-extra, extra, extra
);
}
{
path.arcMoveTo(rect, 0);
path.arcTo(rect, 0, 180);
return path;
}
{
mybrush.setStyle(Qt::NoBrush);
mypen.setWidth(2);
if(hover)
{
mypen.setColor(Qt::red);
}
else
{
mypen.setColor(Qt::black);
}
painter
->setRenderHint
(QPainter::Antialiasing,
true);
painter->setPen(mypen);
painter->setBrush(mybrush);
path.arcMoveTo(rect, 0);
path.arcTo(rect, 0, 180);
setPath(path);
painter->drawPath(path);
}
{
hover = true;
update();
}
{
hover = false;
update();
}
#include "item.h"
Item::Item()
{
hover = false;
setAcceptHoverEvents(true);
}
QRectF Item::boundingRect() const
{
qreal extra = (pen().width() + 20) / 2.0;
return QRectF(path().boundingRect()).normalized().adjusted(-extra, -extra, extra, extra);
}
QPainterPath Item::shape() const
{
QPainterPath path;
QRectF rect(0, 0, 100, 100);
path.arcMoveTo(rect, 0);
path.arcTo(rect, 0, 180);
return path;
}
void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
QPen mypen = pen();
QBrush mybrush;
mybrush.setStyle(Qt::NoBrush);
mypen.setWidth(2);
if(hover)
{
mypen.setColor(Qt::red);
}
else
{
mypen.setColor(Qt::black);
}
painter->setRenderHint(QPainter::Antialiasing,true);
painter->setPen(mypen);
painter->setBrush(mybrush);
QPainterPath path;
QRectF rect(0, 0, 100, 100);
path.arcMoveTo(rect, 0);
path.arcTo(rect, 0, 180);
setPath(path);
painter->drawPath(path);
}
void Item::hoverEnterEvent(QGraphicsSceneHoverEvent *)
{
hover = true;
update();
}
void Item::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
{
hover = false;
update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks