简体   繁体   中英

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

I have my own QGraphicsScene and two QGraphicView's. In the QGraphicsScene I use the

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). 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. 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(); 
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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