#include <QtGui>
public:
GPS_Site(const QString& text, qreal lon, qreal lat) {
setZValue(2);
label->setFlags(ItemIgnoresTransformations | ItemIsSelectable);
label->setPos(2, 3);
}
};
Q_OBJECT
public:
MainWindow() {
scene->addItem(new GPS_Site("Lower left: A very long text label, bla bla bla bla bla bla bla", 58.111, 24.111));
scene->addItem(new GPS_Site("Upper right: bla bla bla", 58.999, 24.999));
view->setScene(scene);
QMatrix m
(1.0,
0.0,
0.0,
-1.0,
0.0,
0.0);
// identity matrix with reversed Y-axis view->setMatrix( m );
setCentralWidget(view);
}
protected:
qreal scaleFactor = pow((double) 2, -event->delta() / 240.0);
view->scale(scaleFactor, scaleFactor);
}
private:
};
int main(int argc, char *argv[]) {
MainWindow* mainWin = new MainWindow();
mainWin->show();
return app.exec();
}
#include <QtGui>
class GPS_Site : public QGraphicsEllipseItem {
public:
GPS_Site(const QString& text, qreal lon, qreal lat) {
setZValue(2);
QGraphicsEllipseItem::setFlags(ItemIgnoresTransformations | ItemIsSelectable);
QGraphicsEllipseItem::setPos(lon, lat);
QGraphicsEllipseItem::setRect(-5, -5, 10, 10);
QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(text, this);
label->setFlags(ItemIgnoresTransformations | ItemIsSelectable);
label->setPos(2, 3);
}
};
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow() {
QGraphicsScene* scene = new QGraphicsScene();
scene->addItem(new GPS_Site("Lower left: A very long text label, bla bla bla bla bla bla bla", 58.111, 24.111));
scene->addItem(new GPS_Site("Upper right: bla bla bla", 58.999, 24.999));
view = new QGraphicsView(scene);
view->setScene(scene);
QMatrix m(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); // identity matrix with reversed Y-axis
view->setMatrix( m );
setCentralWidget(view);
}
protected:
virtual void wheelEvent(QWheelEvent* event) {
qreal scaleFactor = pow((double) 2, -event->delta() / 240.0);
view->scale(scaleFactor, scaleFactor);
}
private:
QGraphicsView* view;
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
MainWindow* mainWin = new MainWindow();
mainWin->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks