自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Qt中 QTableWidget類設(shè)置表格 實(shí)例

移動(dòng)開發(fā)
本文介紹的是Qt中 QTableWidget類設(shè)置表格 實(shí)例,有關(guān)QTableWidget的更多資料請(qǐng)關(guān)注本文末尾。先來看內(nèi)容

Qt QTableWidget類設(shè)置表格 實(shí)例是本文要介紹的內(nèi)容,如果不是很清楚可以查閱QT類相關(guān)的資料,本文也有推薦。不多說,先來看內(nèi)容。在Qt的Help里面查詢相關(guān)介紹與使用。

Qt中 QTableWidget類設(shè)置表格 實(shí)例

頭文件包含:

  1. #include <QTableWidget> 

具體使用:

  1.     //構(gòu)造一個(gè)QTableWidget類的實(shí)體對(duì)象tableWidget  
  2.      tableWidget = new QTableWidget(ui->textBrowser);  
  3.     tableWidget->setRowCount(7);//設(shè)置行數(shù)為7  
  4.     tableWidget->setColumnCount(5);//設(shè)置列數(shù)為5  
  5.     tableWidget->setGeometry(QRect(0,0,401,241));//設(shè)置tableWidget的大小  
  6.     tableWidget->setItem(0,0,new QTableWidgetItem("abc"));//第一行第一列的內(nèi)容設(shè)置為abc  
  7.     tableWidget->setItem(1,0,new QTableWidgetItem("def"));//第二行第一列的內(nèi)容設(shè)置為abc  
  8. // 40,110,100,60,85  
  9.     tableWidget->setColumnWidth(0,40);//設(shè)置第一列的列寬  
  10.     tableWidget->setColumnWidth(1,110);//設(shè)置第二列的列寬  
  11.     tableWidget->setColumnWidth(2,100);//設(shè)置第三列的列寬  
  12.     tableWidget->setColumnWidth(3,60);//設(shè)置第四列的列寬  
  13.     tableWidget->setColumnWidth(4,85);//設(shè)置第五列的列寬  
  14.     QTextCodec::setCodecForTr(QTextCodec::codecForName("GB18030"));//編碼設(shè)置為GB18030  
  15. // 列表的標(biāo)題----車次 車牌 支付卡 金額 累計(jì)金額  
  16.     tableWidget->setHorizontalHeaderLabels(QStringList() <<tr("車次")<<tr("車牌")<<tr("支付卡")<<tr("金額")<<tr("累計(jì)金額"));  
  17.     tableWidget->setFont(QFont("wenquanyi",12,3));//設(shè)置字體  
  18.     QHeaderView* headerView = tableWidget->verticalHeader();  
  19.     headerView->setHidden(true); //行名隱藏 

由于使用了QTextCodec,所以在上面還應(yīng)該包含頭文件:

  1. #include <QTextCodec> 

小結(jié):QtQTableWidget類設(shè)置表格 實(shí)例的內(nèi)容介紹完了,希望本文對(duì)你有所幫助,關(guān)于相關(guān)內(nèi)容的資料請(qǐng)參考編輯推薦。

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)