#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsEllipseItem>
#include <QWheelEvent>
#include <QStyleOptionGraphicsItem>
public:
setPointSize(2);
setBrush(Qt::red);
setPen(Qt::NoPen);
}
void setPointSize(qreal s) {
setRect(-s, -s, 2*s, 2*s);
}
};
public:
protected:
if(event->delta() > 0) {
scale(1.25, 1.25);
} else {
scale( 0.8, 0.8);
}
}
};
int main(int argc, char *argv[])
{
GraphicsView view;
for(int i=0;i<100000;++i) {
PointItem *item = new PointItem;
item->setPos(qrand() % 10000, qrand() % 5000);
scene.addItem(item);
}
view.setScene(&scene);
view.
setRenderHint(QPainter::Antialiasing);
view.show();
return a.exec();
}
#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsEllipseItem>
#include <QWheelEvent>
#include <QStyleOptionGraphicsItem>
class PointItem : public QGraphicsEllipseItem {
public:
PointItem(QGraphicsItem *parent = 0) : QGraphicsEllipseItem(parent) {
setPointSize(2);
setBrush(Qt::red);
setPen(Qt::NoPen);
setFlag(QGraphicsItem::ItemIgnoresTransformations);
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
}
void setPointSize(qreal s) {
setRect(-s, -s, 2*s, 2*s);
}
};
class GraphicsView : public QGraphicsView {
public:
GraphicsView(QWidget *parent = 0) : QGraphicsView(parent) {}
protected:
void wheelEvent(QWheelEvent *event) {
if(event->delta() > 0) {
scale(1.25, 1.25);
} else {
scale( 0.8, 0.8);
}
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GraphicsView view;
QGraphicsScene scene(0, 0, 10000, 5000);
for(int i=0;i<100000;++i) {
PointItem *item = new PointItem;
item->setPos(qrand() % 10000, qrand() % 5000);
scene.addItem(item);
}
view.setScene(&scene);
view.setRenderHint(QPainter::Antialiasing);
view.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks