#include <QtWidgets>
public:
setRect(0,0,50,50);
}
}
};
public:
protected:
if(e->button() == Qt::LeftButton) scale(2,2);
else scale(0.5, 0.5);
}
};
int main(int argc, char **argv) {
GraphicsView view;
view.setScene(&scene);
scene.addItem(new Item);
view.show();
view.scale(3,3);
return app.exec();
}
#include <QtWidgets>
class Item : public QGraphicsRectItem {
public:
Item(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {
setRect(0,0,50,50);
setPen(QPen(Qt::red));
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) {
qDebug() << "LOD:" << QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
QGraphicsRectItem::paint(painter, option, widget);
}
};
class GraphicsView : public QGraphicsView {
public:
GraphicsView() : QGraphicsView() {}
protected:
void mousePressEvent(QMouseEvent *e) {
if(e->button() == Qt::LeftButton) scale(2,2);
else scale(0.5, 0.5);
}
};
int main(int argc, char **argv) {
QApplication app(argc, argv);
GraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
scene.addItem(new Item);
view.show();
view.scale(3,3);
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks