Important: Please read the Qt Code of Conduct -

QSplitter: how to know when a widget is added/removed form the splitter

  • Hello,
    Is there a signal sent on a widget's addition/removal to the splitter. I tried overriding the QObject::ChildEvent() but i noticed that the splitter count isn't updated when this event is been called(although its been called several times, there isn't a call after QSplitter::count() is updated).
    I want to do some updates on splitter on each widget's add/removal.

    Please see my second post in this thread for the work around.

  • I have never worked with QSplitter so I don't know if this is the problem or not, but did you make sure that you call the default implementation of the QSplitter::childEvent() method in your own override? Something like this:

    void MySplitter::childEvent(QChildEvent* c) {
    	// Call the default implementation
    	// Do my own stuff here

  • Thanks for the reply @Joel-Bodenmann
    Yes i did call QSplitter::childEvent(event),

    but i think child event is getting called after widget reparenting & also on polish events but not after QSplitter::count() is updated.

    Good thing is that i found a work around,

    • I've reimplemented QSplitter::paintEvent() and doing "MAGIC" but i found that paintEvent is called too many times.
    • So, i'm storiing QSplitter::count() in a member variable & updating it on every paintEvent(). With this i was able to "applyMagic()" only when the splitter count() is actually changed.
      I think this isn't an ideal solution but all i need is to "applyMagic()" when the splitter is about to be shown after getting widgets added/removed. (manipulating Qt event handlers to solve our purposes..:) )

Log in to reply