#include <QtGui>
{
public:
{
setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
}
{
QRectF br
= QRectF(mapToScene
(boundingRect
().
topLeft()),boundingRect
().
size());
if(e->buttons() & Qt::RightButton)
rotate(90);
scene()->update(br);
}
{
p->drawLine(-18, -9, 18, -9);
p->drawLine( 18, -9, 18, 9);
p->drawLine( 18, 9,-18, 9);
p->drawLine(-18, 9,-18, -9);
p->drawLine(-30, 0,-18, 0);
p->drawLine( 18, 0, 30, 0);
}
{
}
};
int main(int argc, char *argv[])
{
view
->setRenderHint
(QPainter::Antialiasing);
Rotor *r = new Rotor(&scene);
r->setPos(125,125);
r = new Rotor(&scene);
r->setPos(57,75);
view->show();
return app.exec();
}
#include <QtGui>
class Rotor : public QGraphicsItem
{
public:
Rotor(QGraphicsScene *s) : QGraphicsItem(0l,s)
{
setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
}
void mousePressEvent(QGraphicsSceneMouseEvent * e)
{
QRectF br = QRectF(mapToScene(boundingRect().topLeft()),boundingRect().size());
if(e->buttons() & Qt::RightButton)
rotate(90);
scene()->update(br);
QGraphicsItem::mousePressEvent(e);
}
void paint(QPainter *p,const QStyleOptionGraphicsItem * , QWidget *)
{
p->drawLine(-18, -9, 18, -9);
p->drawLine( 18, -9, 18, 9);
p->drawLine( 18, 9,-18, 9);
p->drawLine(-18, 9,-18, -9);
p->drawLine(-30, 0,-18, 0);
p->drawLine( 18, 0, 30, 0);
}
QRectF boundingRect() const
{
return QRectF(-30,-9,60,18);
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QGraphicsScene scene(0,0,250,250);
QGraphicsView* view = new QGraphicsView(&scene);
view->setRenderHint(QPainter::Antialiasing);
Rotor *r = new Rotor(&scene);
r->setPos(125,125);
r = new Rotor(&scene);
r->setPos(57,75);
view->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks