classQWDCurrentView :publicQWidget
{
public:
QWDCurrentView(void);
public:
~QWDCurrentView(void);
public:
voidGetCurrentValues(STREAMLINE¤tValue);//得到某一回線的電流相關信息
voidSetCurrentValues(STREAMLINEcurrentValue);//設置某一回線的電流相關信息
private:
voidInitView(QStringListrowHeader,QStringListcolHeader);
private:
QTableWidget*m_tableWidget;
};
QWDCurrentView::QWDCurrentView(void)
{
setMinimumSize(1000,400);
setMaximumSize(1000,400);
QStringListcolHeader;
colHeader.clear();
for(inti = 0; i < LINENUM; i++)
{
colHeader.append(QString("%1").arg(i));
}
QStringListrowHeader;
rowHeader.append("線路號");
rowHeader.append("類別(電壓或電壓)");
rowHeader.append("值(V或A)");
rowHeader.append("PT/CT變比");
rowHeader.append("角度");
rowHeader.append("撥碼開關");
m_tableWidget= newQTableWidget(this);
InitView(rowHeader,colHeader);
QHBoxLayout*mainLayout = newQHBoxLayout;
mainLayout->addWidget(m_tableWidget);
setLayout(mainLayout);
//(m_tableWidget->horizontalHeader())->setResizeMode(QHeaderView::Stretch);
}
在構造這個窗體時如果不加這句話會出現出下結果,見附件1
在這個窗體的最後面有一塊空白的地方,相當的難看。我們在開頭限制了列表父窗體的大小,如果列表寬度與父窗體寬度不一至就會出現這個情況了。解決方法有如下幾種:
(1)測試法。通過一個數一個數的逼進來達到父窗體與列表的寬度一至,比如這個我試着改爲953時就能達到這個效果了,但是在別的設備上是不是這個樣子還不確定了。
(2)得到水平列頭的寬度,然後加上每一行所需要的寬度。可行,但是過程比較繁鎖。本人沒有實現成功。
(3)通過設置其自動調整法。也就是加上紅色標註的地方,使水平表頭自動調整寬度,就可以達到這個效果了。
最終採取第三種方式,見附件2
其實如果要修改垂直可以將紅色標準處改爲如下:
(m_tableWidget-> verticalHeader())->setResizeMode(QHeaderView::Stretch)