簡體   English   中英

在Qt中從第二個graphicsview的場景中忽略drawForeground()

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

我有自己的QGraphicsScene和兩個QGraphicView。 在QGraphicsScene中,我使用

drawForeground(QPainter *painter, const QRectF &rect)

繪制網格的功能。 現在我只希望網格在第一個視圖中可見,而在第二個視圖中不可見……這可能嗎?

QGraphicsView是通向世界的窗口(QGraphicsScene)。 您要問的是說在窗戶外面看時正在下雨,但是當我透過窗戶之一看時只能下雨嗎?

但是,您可以更改窗簾(!),因此可以重寫QGraphicsView而不是QGraphicsScene的功能。 我建議使用此:-

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

將此僅應用於您要更改的視圖。 對於兩個視圖,您將需要一個標志來設置要將其應用於哪個視圖。 例如: -

 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