Problems with Splitters
-
Hi,
I'd appreciate any guidance here.
I have a program with a tab view and on each of the tabs there are horizontal splitters. At program start I want to set the width of the left side of the splitters to a value (e.g. 360) that I know is < half the width of the MainWindow (e.g. 900). (Using these example numbers, I would call setSizes() with 360 and 900-360 = 540.)
Initially I called setSizes() in the MainWindow constructor and found it didn't work; I presume because the splitters haven't been rendered yet and therefore the size available to them isn't know. I then added code to do one-time set in the showEvent() and an everytime set in the resizeEvent(). This works! However....
On rare occasions I find one of the splitters still isn't set correctly. It's always the same one and its split point is completed to the right hand side, as if the width available was extremely small (< 100) and my setting code set the widths to [360, 100-360 = -260] which is clearly invalid.
The problem only appears occasionally when running a release build, and so I can't debug it.
One other caveat, in the MainWindow constructor I remove some tabs (which contain splitters) from the tab view, depending on a mode of the program, and the splitter with the problem is one of these tabs which is not attached to the tab view when showEvent() is called. (showEvent() still does set its sizes.) Later switching the program mode causes this tab and some others to be reinserted into the tab view, but only one of these reinserted tabs has a problem with its splitter.
So I guess my question are;
- when is the best time to call splitter setSizes() to set the initial split point?
- what does setSizes() do if the splitter (or its parent widget) is not directly associated with the tab view? Are they still children and therefore get sent size information? In my experience the setSizes() still works 99% of the time.
Thanks,
-
Hi,
Does that widget triggering the issue have anything special in it ?
-
Ok, I returned to these splitters again and discovered something new.
When QSplitters are on tabs in a QTabWdiget, the splitters don't set up their layout until the tab is visible, and so it's impossible to force a splitter handle location until the first time the tab (containing the splitter) is visible.
So for each tab in my application, I have to use a unique "first show" boolean which I use to set the splitter split position on QTabWidget::currentChanged(int).