Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 忽略qt中第二个graphicsview上的场景中的drawForeground()_C++_Qt_Qgraphicsview_Qgraphicsscene - Fatal编程技术网

C++ 忽略qt中第二个graphicsview上的场景中的drawForeground()

C++ 忽略qt中第二个graphicsview上的场景中的drawForeground(),c++,qt,qgraphicsview,qgraphicsscene,C++,Qt,Qgraphicsview,Qgraphicsscene,我有自己的QGraphicscene和两个QGraphicView。在Qgraphicscene中,我使用 drawForeground(QPainter *painter, const QRectF &rect) 函数来绘制网格。现在我只希望网格在第一个视图中可见,但在第二个视图中不可见……这可能吗?QGraphicsView是一个世界窗口(QGraphicsCenter)。你问的就像是说当我看窗外时正在下雨,但我只能透过其中一扇窗户看时才会下雨 但是,您可以更改窗帘(!),以便覆盖

我有自己的QGraphicscene和两个QGraphicView。在Qgraphicscene中,我使用

drawForeground(QPainter *painter, const QRectF &rect)

函数来绘制网格。现在我只希望网格在第一个视图中可见,但在第二个视图中不可见……这可能吗?

QGraphicsView是一个世界窗口(QGraphicsCenter)。你问的就像是说当我看窗外时正在下雨,但我只能透过其中一扇窗户看时才会下雨

但是,您可以更改窗帘(!),以便覆盖QGraphicsView的功能,而不是QGraphicsCenter。我建议使用以下方法:-

QGraphicsView::drawForeground(QPainter *, const QRectF &);
仅将此应用于要更改的视图。对于两个视图,您需要一个标志来设置要将其应用于哪些视图。例如:-

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

谢谢,这很有效。我不敢相信我没有在视图中搜索drawForeGround()。。