tags:

views:

47

answers:

1

Say I have a window, where there are 2 horizontal sppliters, and a button. How to move a splitter up/down by clicking on the button?

+3  A: 

Take a look at http://doc.trolltech.com/4.6/qsplitter.html#setSizes. The main point is that there is no method to move the splitter explicity, you can only achieve similar behaviour by resizing the widgets in the QSplitter themselves, which is easily accomplished by using QSplitter::setSizes. I would do something like

QList<int> currentSizes = mySplitter->sizes();
// adjust sizes individually here, e.g.
currentSizes[0]++;
currentSizes[1]--;
mySplitter->setSizes(currentSizes);

which would move a horizontal splitter with two widgets by one pixel. You would have to add a check to avoid negative sizes, of course.

Greg S