나는 비슷한 것을하려고합니다. 하나의 고정 된 위젯 (상단)과 하나의 고정되지 않은 위젯 (하단)이 있습니다. 사용자가 스플리터 핸들을 정상적으로 사용할 수있게하고 싶지만 창 크기를 조정하여 고정 위젯에 공간을 추가하지 않으려합니다. 두 위젯 모두에서 setSizePolicy를 사용하면 나에게 적합하지 않으며 두 위젯 중 하나 또는 둘 모두에서 setStretchFactor를 사용하지 않았습니다.
스플리터 크기를 조정 한 후에 스플리터를 움직일 resizeEvent를 구현할 수 있도록 QSplitter를 서브 클래 싱하는 작업이 끝났습니다. 이 코드는 다음을 전제로합니다 : 두 개의 위젯 만 있습니다. 위쪽 [0]은 크기 조정 가능하고 아래쪽 [1]은 없어야합니다.
MySplitter::resizeEvent(QResizeEvent *event) {
/* The first resizeEvent is -1 for height and width, because it was
invisible before. */
if (event->oldSize().height() != -1) {
int diff;
QList<int> previousSizes = sizes();
QSplitter::resizeEvent(event);
QList<int> newSizes = sizes();
/* The bottom widget is the fixed one, so find out if that is to
grow or shrink. */
diff = newSizes[1] - previousSizes[1];
if (diff > 0) {
/* Keep the bottom from growing by giving the size to the top. */
newSizes[0] += diff;
newSizes[1] -= diff;
}
else {
/* Steal size from the top to keep it from shrinking. */
newSizes[0] -= diff;
newSizes[1] += diff;
}
setSizes(newSizes);
}
else
QSplitter::resizeEvent(event);
}
: 여기
내가 쓴 resizeEvent입니다