开发者

How to move QSplitter?

开发者 https://www.devze.com 2023-01-04 18:54 出处:网络
Say I have a window, where thereare 2 horizontal sppliters, and a button. How to move a splitter up/down by clicking o开发者_Python百科n the button?Take a look at http://doc.qt.io/qt-4.8/qsplitter.htm

Say I have a window, where there are 2 horizontal sppliters, and a button. How to move a splitter up/down by clicking o开发者_Python百科n the button?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号