Why I don't get a resizeEvent immediately after showFullScreen() ?



  • I am calling showFullScreen() on a QGraphicsView; update various things in the QGraphicsScene for full screen and then finally my view actually receives a resize event.

    I tried adding a processEvents() but that does not help.

    I need the resizeEvent because I want to get the actual size of the view before updating things in the scene.


  • Qt Champions 2016

    @kegon
    Well, update the scene after you receive the event. No one is guaranteeing you in what order the events are appearing as it may differ from platform to platform.

    This should help you:

    class GraphicsViewMonitor : public QObject
    {
        Q_OBJECT
    
    signals:
        void graphicsViewResized(QGraphicsView *, QSize);
    
    protected:
        virtual bool eventFilter(QObject * object, QEvent * e)
        {
             if (e->type() == QEvent::Resize)  {
                 QGraphicsView * view = qobject_cast<QGraphicsView *>(object);
                 QResizeEvent * event = reinterpret_cast<QResizeEvent *>(e);
                 if (view)
                     emit graphicsViewResized(view, event->size());
             }
             return false;
        }
    };
    
    // Set the event filter up
    GraphicsViewMonitor viewMonitor;
    
    QGraphicsView view;
    view.installEventFilter(&viewMonitor);
    
    // Use with a queued connection
    QObject * updaterObject; //< This is the object that updates the scene
    QObject::connect(&viewMonitor, SIGNAL(graphicsViewResized(QGraphicsView *, QSize)), updaterObject, SLOT(updateSceneOnResize(QGraphicsView *, QSize)), Qt::QueuedConnection);
    


  • @kshegunov

    I think you're right. I was confused because it appeared that I was getting the resizeEvent after the widget was drawn full screen; but that can't be possible.

    Thanks for the example, that's very helpful.


  • Qt Champions 2016

    @kegon
    The thing is as I mentioned you can't rely on their order of appearance (and you shouldn't). For example on my machine I've noticed (sometime ago when debugging) I receive 2 resize events (one with 0, 0 size), then I get the show event and then the paint event. You'd say that (0, 0) resize event is invalid but it's not quite so. If I understand correctly (the Qt source), on X11 (which is what I have) the determination of widget geometry is speculative (so I get seemingly invalid size events) then when everything is set up it works fine. So in conclusion: don't rely on the order of events, only respond to the them!

    Kind regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.