
Originally Posted by
Quasimojo
Maybe the method of using the QGraphicsView to accomplish this just isn't apparent to me, but I don't see how that would produce the desired result.
#include <QtGui>
public:
protected:
fitInView(sceneRect(), Qt::KeepAspectRatio);
}
};
int main(int argc, char**argv) {
View view;
scene.setSceneRect(0,0,100,100);
f.setPointSize(3);
for(int r = 0; r < 10; ++r) {
for(int c = 0; c < 10; ++c) {
item->setPos(c*10,r*10);
}
}
view.setScene(&scene);
view.resize(600,400);
view.
setRenderHints(QPainter::Antialiasing|QPainter
::TextAntialiasing);
view.show();
return app.exec();
}
#include <QtGui>
class View : public QGraphicsView {
public:
View(QWidget *parent = 0) : QGraphicsView(parent) {}
protected:
void resizeEvent(QResizeEvent *e) {
QGraphicsView::resizeEvent(e);
fitInView(sceneRect(), Qt::KeepAspectRatio);
}
};
int main(int argc, char**argv) {
QApplication app(argc, argv);
View view;
QGraphicsScene scene;
scene.setSceneRect(0,0,100,100);
QFont f = view.font();
f.setPointSize(3);
for(int r = 0; r < 10; ++r) {
for(int c = 0; c < 10; ++c) {
QGraphicsSimpleTextItem *item = scene.addSimpleText(QString("%1-%2").arg(r).arg(c), f);
item->setPos(c*10,r*10);
}
}
view.setScene(&scene);
view.resize(600,400);
view.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks