Created
September 13, 2012 13:49
-
-
Save Atsushi4/3714416 to your computer and use it in GitHub Desktop.
QGraphicsViewの表面にテキストを表示するサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtGui> | |
class Window : public QGraphicsView | |
{ | |
Q_OBJECT | |
public: | |
Window() { | |
setScene(new QGraphicsScene(-200, -200, 400, 400)); | |
setDragMode(ScrollHandDrag); | |
drawMesh(); | |
resize(200, 200); | |
setViewportUpdateMode(FullViewportUpdate); | |
} | |
protected: | |
void paintEvent(QPaintEvent *event) { | |
QPainter p(this); | |
p.drawText(QRect(0, 0, width() - 20, p.font().pointSize()), "hogehoge", QTextOption(Qt::AlignTop | Qt::AlignRight)); | |
QGraphicsView::paintEvent(event); | |
} | |
private: | |
void drawMesh() { | |
const QRectF rect = scene()->sceneRect(); | |
for (int i = rect.left(); i <= rect.right(); i += 10) | |
scene()->addLine(i, rect.top(), i, rect.bottom()), scene()->addLine(rect.left(), i, rect.right(), i); | |
} | |
}; | |
int main(int argc, char **argv) | |
{ | |
QApplication app(argc, argv); | |
Window w; | |
w.show(); | |
return app.exec(); | |
} | |
#include "text_on_graphicsview.moc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment