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