2013-01-18 4 views
5

QSplitter에 고정 크기의 위젯과 가변 크기의 위젯이있을 수 있습니까? 하나의 고정 크기 위젯과 하나의 가변 크기 위젯을 가진 QSplitter?

이 코드

는 것을 잘 설정하지만 윈도우가 초기 위젯의 크기에 비례하여 분할 변경의 크기를 조정할 때 :

vSplitter = new QSplitter(Qt::Vertical, this); 
vSplitter->addWidget(widget1); 
vSplitter->addWidget(widget2); 
QList<int> heights; 
heights.push_back(550); 
heights.push_back(1000); 
vSplitter->setSizes(heights); 

setCentralWidget(vSplitter); 

감사합니다.

답변

12

이 하나를 시도

QSplitter::setStretchFactor (int index, int stretch)

그냥 0으로 고정 된 크기를 유지하고 다른 위젯을 1로 설정하고자하는 부분의 신축성 계수를 설정합니다.

전체 창 크기를 조정할 때 늘이기 인수 0 인 위젯의 크기가 조정되지 않습니다.

0

나는 비슷한 것을하려고합니다. 하나의 고정 된 위젯 (상단)과 하나의 고정되지 않은 위젯 (하단)이 있습니다. 사용자가 스플리터 핸들을 정상적으로 사용할 수있게하고 싶지만 창 크기를 조정하여 고정 위젯에 공간을 추가하지 않으려합니다. 두 위젯 모두에서 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입니다