Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is there a "layout complete" event?



  • I am making a simple multi-page document viewer. I have an initially empty QScrollArea, to whose layout I add
    several (or many) QLabel widgets. I create and size these QLabels and add them to the layout in a loop, which does not take long.

    The problem is that right after this, I try and determine which ones are visible within the QScrollArea using
    visibleRegion(), but none of them appear visible. If, however, I go away for 200 msec (using a QTimer)
    and try again, I then get the results I expect.

    So, question: how can I determine exactly when the sizing/layout of these QLabels is actually done?

    Thanks.


  • Lifetime Qt Champion

    Hi,

    You could use the showEvent method from your QScrollArea container.



  • Thanks for your reply. I was able to put an event filter on the scroll area's content widget, and watch for QEvent::LayoutRequest.


  • Lifetime Qt Champion

    Nice, but AFAIK, that event means that the layout should be updated, not that it has already happened


Log in to reply