[英]Ignore drawForeground() from the scene on the 2nd graphicsview in qt
[英]Qt GraphicsView stretch scene to fit
好的,所以我使用Qt和C ++作为我的环境。
我在我的UI中绘制了一个QGraphicsView
。
然后我创建一个场景并为该场景添加线条。 我运行5000点的数组并画出连接每个点的线。
QGraphicsScene *scene = new QGraphicsScene();
QPen pen2 = QPen(Qt::blue, 8.0);
int j=1;
for (int i=1; i<5000; i++)
{
scene->addLine(xArray[i],yArray[i],xArray[j],yArray[j], pen2);
j++;
}
问题是我抓到的数字非常小,例如2.000e-12。 这些数字将根据应用程序不断变化。 如何调整我的场景以拉伸以填充我的QGraphicsView
。 现在,我看到的只是我视角中心的一个点。 我有道理吗?
使用sceneRect在QGraphicsScene中的QGraphicsView :: fitInView()会做缩放到适合你。
我自己从未使用它,但在Qt doc中有一个
void QGraphicsView::scale ( qreal sx, qreal sy )
允许您在x和y轴上缩放视图。 如果还不够,你可以(如果你的项目中有可能)在值太小或太大时手动缩放,当你绘制线条并将相同的因子应用于其他所有因素时。 但是如果有可能的话,我会选择Qt中包含的比例法。
希望这可以帮助。
检查此代码是否有帮助。 它只适合GraphicsView上的图像
m_Scene.setSceneRect(m_QImage.rect());
m_Scene.addPixmap(QPixmap::fromImage(m_QImage,0));
m_GraphicsView.setScene(&m_Scene);
m_GraphicsView.fitInView(m_QImage.rect());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.