简体   繁体   English

在Qt中从第二个graphicsview的场景中忽略drawForeground()

[英]Ignore drawForeground() from the scene on the 2nd graphicsview in qt

I have my own QGraphicsScene and two QGraphicView's. 我有自己的QGraphicsScene和两个QGraphicView。 In the QGraphicsScene I use the 在QGraphicsScene中,我使用

drawForeground(QPainter *painter, const QRectF &rect)

function to draw a grid. 绘制网格的功能。 Now I want the grid only to be visible in the first, but not in the second view…is this possible? 现在我只希望网格在第一个视图中可见,而在第二个视图中不可见……这可能吗?

The QGraphicsView is a window into a world (the QGraphicsScene). QGraphicsView是通向世界的窗口(QGraphicsScene)。 What you're asking would be like saying that it's raining when I look outside my windows, but can I have it only rain when I look through one of them?! 您要问的是说在窗户外面看时正在下雨,但是当我透过窗户之一看时只能下雨吗?

However, you can change the curtains(!), so override the function of the QGraphicsView, rather than the QGraphicsScene. 但是,您可以更改窗帘(!),因此可以重写QGraphicsView而不是QGraphicsScene的功能。 I suggest using this: - 我建议使用此:-

QGraphicsView::drawForeground(QPainter *, const QRectF &);

Apply this just to the view you want to change. 将此仅应用于您要更改的视图。 With two views, you'll need a flag to set which of the views you want to apply this to. 对于两个视图,您将需要一个标志来设置要将其应用于哪个视图。 For example: - 例如: -

 void MyGraphicsView::drawForeground(QPainter* painter, const QRectF& rect)
 {
     QGrahicsView::drawForeground(painter, rect);
     if(m_bDrawGrid)
         DrawGrid(); 
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM