0
私は、ユーザーがマウスでいくつかの点を描くことができるアプリケーションを持っており、QGraphicsViewを使ってそれを行いました。QGraphicsViewのシーンを描画するには?
私はQGraphicsView内のシーンを初期化:
scene = new QGraphicsScene(this); scene->setItemIndexMethod(QGraphicsScene::NoIndex); scene->setSceneRect(0, 0, 850, 480); setScene(scene); setCacheMode(CacheBackground); setViewportUpdateMode(BoundingRectViewportUpdate); setRenderHint(QPainter::Antialiasing); setTransformationAnchor(AnchorUnderMouse); scale(qreal(1.0), qreal(1.0)); setMinimumSize(400, 400);
をこのシーンは全体QGraphicsViewをカバーしていないと私は、ユーザーが唯一のシーン上の点を描くことができるようにしたいです。また、ポイントの座標はQGraphicsViewエリアではなく、シーンからの座標でなければなりません。
これは、1つのscreenshotです!それはどのように見えるの。
私はこのようにやってみました:私は、座標をテストしてい
QPoint p = event->pos(); QRectF sceneRect = this->sceneRect(); if ((p.x() > sceneRect.left())&&(p.x() < sceneRect.right())&&(p.y() > sceneRect.top())&& (p.y() < sceneRect.bottom())){ QMessageBox msg; msg.setText("point is: " + QString::number(p.x()) + ", " + QString::number(p.y())); msg.exec(); }
。しかし、正しい結果は返されません。 シーンにのみ描画するようにユーザーを制限するにはどうすればよいですか?