Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move QSplitter?

Tags:

c++

qt

qsplitter

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?

like image 742
Narek Avatar asked Jun 28 '10 08:06

Narek


1 Answers

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.

like image 151
Greg S Avatar answered Sep 21 '22 20:09

Greg S