#include <QtGui>
public:
p.setCosmetic(true);
painter->setPen(p);
qreal lod = option->levelOfDetail;
qreal left = rect().left();
qreal wid = rect().width();
if(lod>=0.2)
for(qreal i = 0; i<wid;i+=10.0){
painter
->drawLine
(QLineF(left
+i, rect
().
bottom(), left
+i, rect
().
bottom()-10));
if(lod>=1.0){
for(qreal j = 1.0; j<5; j+=1.0){
painter
->drawLine
(QLineF(left
+i
+2*j, rect
().
bottom(), left
+i
+2*j, rect
().
bottom()-5));
if(lod>=4){
for(qreal k = 0.4; k<2.0; k+=0.4){
painter
->drawLine
(QLineF(left
+i
+2*j
+k, rect
().
bottom(), left
+i
+2*j
+k, rect
().
bottom()-2));
}
}
}
}
}
}
};
public:
protected:
int delta = e->delta();
if(delta>0) scale(1.2, 1.2);
else if(delta<0) scale(1.0/1.2, 1.0/1.2);
}
};
int main(int argc, char **argv){
GraphicsView view;
ResItem *item = new ResItem;
item->setRect(-50, -50, 300, 100);
view.scene()->addItem(item);
item->setPos(300,250);
view.show();
return app.exec();
}
#include <QtGui>
class ResItem : public QGraphicsRectItem {
public:
ResItem() : QGraphicsRectItem(){}
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ){
QPen p = painter->pen();
p.setCosmetic(true);
painter->setPen(p);
QGraphicsRectItem::paint(painter, option, widget);
qreal lod = option->levelOfDetail;
qreal left = rect().left();
qreal wid = rect().width();
if(lod>=0.2)
for(qreal i = 0; i<wid;i+=10.0){
painter->drawLine(QLineF(left+i, rect().bottom(), left+i, rect().bottom()-10));
if(lod>=1.0){
for(qreal j = 1.0; j<5; j+=1.0){
painter->drawLine(QLineF(left+i+2*j, rect().bottom(), left+i+2*j, rect().bottom()-5));
if(lod>=4){
for(qreal k = 0.4; k<2.0; k+=0.4){
painter->drawLine(QLineF(left+i+2*j+k, rect().bottom(), left+i+2*j+k, rect().bottom()-2));
}
}
}
}
}
}
};
class GraphicsView : public QGraphicsView {
public:
GraphicsView():QGraphicsView(){}
protected:
void wheelEvent(QWheelEvent *e){
int delta = e->delta();
if(delta>0) scale(1.2, 1.2);
else if(delta<0) scale(1.0/1.2, 1.0/1.2);
}
};
int main(int argc, char **argv){
QApplication app(argc,argv);
GraphicsView view;
view.setScene(new QGraphicsScene(0,0,600,400));
ResItem *item = new ResItem;
item->setRect(-50, -50, 300, 100);
view.scene()->addItem(item);
item->setPos(300,250);
item->setFlag(QGraphicsItem::ItemIsMovable);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks