[Qt-interest] How to know which instance of QGraphicsView is the active view of a scene?

noam.rosenthal at nokia.com noam.rosenthal at nokia.com
Thu Jun 30 03:45:36 CEST 2011


On Jun 29, 2011, at 6:46 AM, ext fog public wrote:

> Hi all,
>       In Qt's document, I can get a QList of QGraphicsView* that display the scene thought views(). but Which one is actived ? ( which view is currently responsed for  drawing the content of the scene.), thanks a lot.
> <ATT00001..txt>

Assuming you have access to the item's paint function:

void MyGraphicsItem::paint(painter, option, widget) {
   QGraphicsView* whichView = 0;
   for (int i = 0; i < scene()->views().size(); ++i)
        if (scene->views()[i]->viewport() == widget)
            whichView = scene->views()[i];
}

There's probably a nicer way to code this, but this is the direction.
No'am 




More information about the Qt-interest-old mailing list