2013-03-08 41 views
1

我有一個QMainWindow。QMainWindow調整大小時QTableView不擴展/減少

在QMainWindow中,我有一箇中心部件。

對於中央小部件,我有一個QVBoxLayout。

對於此QVBoxLayout,我添加了3個小部件。一個是帶有一些標籤的小部件,它有一個QGridLayout。另一個是水平線。

第三個是QTableView。問題是,當我嘗試擴展QMainWwindow時,儘管我設置了(或不是)任何調整策略,但TableView不會展開,並且在展開後的QMainWindow的其餘部分留下了空白的區域。

任何人都可以告訴我如何使窗口擴大/調整窗口調整大小。

這裏是相關的代碼。

`

statInfoWidget = new Static_Info(TagN); 
QWidget *widget = new QWidget; 
setCentralWidget(widget); 
QFrame *hor_line = new QFrame(); 
hor_line->setFrameShape(QFrame::HLine); 
QVBoxLayout *layout = new QVBoxLayout(); 
layout->setMargin(2); 

layout->addWidget(statInfoWidget); 
layout->addWidget(hor_line); 
Table = new QTableView(this); 
temp = Table; 
t = new TableLayout(statInfoWidget); 
Table->setModel(t); 
Table->verticalHeader()->hide(); 
Table->horizontalHeader()->hide(); 
Table->setShowGrid(false); 
Table->setContextMenuPolicy(Qt::CustomContextMenu); 
//Table->setColumnWidth(2,290); 
// Table->setColumnWidth(0,25); 
// if(num_version == 1) 
//  Table->setColumnWidth(1,0); 
// else 
// Table->setColumnWidth(1,43); 
// Table->setColumnWidth(3,210); 
// Table->setColumnWidth(4,170); 
// Table->setColumnWidth(5,50); 
statInfoWidget->setStyleSheet("background: rgb(153,185,193);color:rgb(0,0,0); font-family:Tahoma;font-size:19px; border: 0px outset rgb(255,255,255);gridline-color: #669933;" 
         "selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #486909, stop: 1 white);"); 
Table->setStyleSheet("background: rgb(153,185,193);color:rgb(0,0,0); font-family:Tahoma;font-size:15px; font-weight:bold; border: 0px outset rgb(255,255,255);gridline-color: #669933;" 
         "selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 transparent, stop: 1 white);"); 
// layout->addWidget(button1); 
QSizePolicy policy = Table->sizePolicy(); 
policy.setVerticalStretch(1); 
policy.setHorizontalStretch(1); 
Table->setSizePolicy(policy); 
layout->addWidget(Table); 
widget->setLayout(layout); 

`

+0

有什麼想法嗎? – user1173240 2013-03-15 10:10:54

回答

2

您可以考慮以下幾點:

Table->horizontalHeader()->setResizeMode(QHeaderView::Stretch); 

你也可以在你的表來調整隻是一個單一的列,這可以通過將完成列索引:

Table->horizontalHeader()->setResizeMode(columnIndex, QHeaderView::Stretch); 
+0

第一種方法確實拉伸了表格,但它覆蓋了我需要爲不同列顯示的固定列寬度。在應用這個之後,所有列都有相同的大小,與總窗口大小相等,並且整個外觀變得凌亂。我需要列的固定最小尺寸才能夠顯示手頭的東西。 – user1173240 2013-03-11 07:04:54

+0

任何解決方案,請? – user1173240 2013-03-14 03:56:32