2017-02-25 4 views

답변

1

Qt에는이 기능이 내장되어 있지 않으므로 수동으로 크기를 계산하고 설정해야합니다.

이것은 수직 크기 조정 (Qt 5.8)에서 사용하는 방법입니다. setMaximumHeight/width를 추가 할 수 있습니다.

추가로 개발하려면 크기에 추가하기 전에 가로 스크롤 막대가 있는지 확인해야합니다. 그래도 내 사용에는 충분하다.

void verticalResizeTableViewToContents(QTableView *tableView) 
{ 
    int count=tableView->verticalHeader()->count(); 
    int scrollBarHeight=tableView->horizontalScrollBar()->height(); 
    int horizontalHeaderHeight=tableView->horizontalHeader()->height(); 
    int rowTotalHeight=0; 
    for (int i = 0; i < count; ++i) { 
     rowTotalHeight+=tableView->verticalHeader()->sectionSize(i); 
    } 
    tableView->setMinimumHeight(horizontalHeaderHeight+rowTotalHeight+scrollBarHeight); 
} 
관련 문제