Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why I don't get a resizeEvent immediately after showFullScreen() ?
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicsviewlinux
4 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kegon
    wrote on last edited by
    #1

    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.

    kshegunovK 1 Reply Last reply
    0
    • K kegon

      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.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @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);
      

      Read and abide by the Qt Code of Conduct

      K 1 Reply Last reply
      1
      • kshegunovK kshegunov

        @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);
        
        K Offline
        K Offline
        kegon
        wrote on last edited by
        #3

        @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.

        kshegunovK 1 Reply Last reply
        0
        • K kegon

          @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.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @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.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved