How to move QSplitter?
Asked Answered
V

1

9

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?

Vision answered 28/6, 2010 at 8:32 Comment(0)
S
16

Take a look at http://doc.qt.io/qt-4.8/qsplitter.html#setSizes. The main point is that there is no method to move the splitter explicitly, 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.

Steelworks answered 28/6, 2010 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.