第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問在qt中 QSqlQueryModel 列寬根據(jù)內(nèi)容改變?

請問在qt中 QSqlQueryModel 列寬根據(jù)內(nèi)容改變?

慕蓋茨4494581 2019-07-01 10:06:56
qt中 QSqlQueryModel 列寬根據(jù)內(nèi)容改變
查看完整描述

4 回答

?
largeQ

TA貢獻2039條經(jīng)驗 獲得超8個贊

Qt幫助文檔里都是用QTabView顯示QSqlQueryModel里的數(shù)據(jù)的,
真要按內(nèi)容改寬度很麻煩,因為不同數(shù)據(jù)長度差距太大,從幾字節(jié)到幾百字節(jié)可能都有。
所以可以間接一點處理,你對列寬合適的寬度做一個估值,
比如顯示日期加時間20字節(jié)的樣子,大概寬度比如200,
用QTableView 的:
void QTableView::setColumnWidth ( int column, int width )
把每個列寬估計一個寬度,設(shè)置一下每個列寬,
看起來差不多就行了。

又找了一下,好像找到你要的函數(shù)了:
void QTableView::resizeColumnsToContents () [slot]

Resizes all columns based on the size hints of the delegate used to render each item in the columns.

Resizes all rows based on the size hints of the delegate used to render each item in the rows.

你調(diào)用resizeColumnsToContents函數(shù)試試看效果。

查看完整回答
反對 回復(fù) 2019-07-14
?
千萬里不及你

TA貢獻1784條經(jīng)驗 獲得超9個贊

QHeaderView *headerView = tableView->verticalHeader();
headerView->setHidden(true);
QStringList header;
header<<tr("Name")<<tr("Path")<<tr("隨便改");
tableView->setHorizontalHeaderLabels(header);

查看完整回答
反對 回復(fù) 2019-07-14
?
慕斯709654

TA貢獻1840條經(jīng)驗 獲得超5個贊

  • 用qsqltablemodel的insetrow()、setdata()、submitall()函數(shù)實現(xiàn)增;

   officeTable->insertRow(0);

   officeTable->setData(officeTable->index(0, 0), row);

   officeTable->setData(officeTable->index(0, 1), newWnd->imageFileEditor->currentIndex());

   officeTable->setData(officeTable->index(0, 2), newWnd->locationText->text());

   officeTable->setData(officeTable->index(0, 3), newWnd->countryText->currentText());

   officeTable->setData(officeTable->index(0, 4), newWnd->descriptionEditor->toPlainText());

   officeTable->submitAll();

 

  • 用removerow()、submitall()函數(shù)實現(xiàn)刪;

   int officeCount = officeTable->rowCount();

   officeTable->removeRow(id);

   for(int i = id; i < officeCount - 1;i++)

   {

    officeTable->setData(officeTable->index(i, 0), i);

   }

   officeTable->submitAll();


  • 用QSqlRecord類的setvalue實現(xiàn)改;

    QSqlRecord recordCurrentRow = officeTable->record(id);

    recordCurrentRow.setValue("id", id - 1);

    officeTable->setRecord(id - 1, recordCurrentRow);

    officeTable->submitAll();

 

  • 用QSqlRecord類的.value進行比較實現(xiàn)查;

  int Dialog::findArtistId(const QString &artist)

  {

      QSqlTableModel *artistModel = model->relationModel(2);

    int row = 0;

 

      while (row < artistModel->rowCount()) {

          QSqlRecord record = artistModel->record(row);

          if (record.value("artist") == artist)

              return record.value("id").toInt();

          else

              row++;

      }

      return addNewArtist(artist);

}

 





查看完整回答
反對 回復(fù) 2019-07-14
?
MMTTMM

TA貢獻1869條經(jīng)驗 獲得超4個贊

ui->tableView->setSortingEnabled(true);
ui->tableView->horizontalHeader()->setSortIndicator(1,Qt::AscendingOrder);

QSortFilterProxyModel *sqlproxy = new QSortFilterProxyModel(this);
sqlproxy->setSourceModel(m_model);
ui->tableView->setModel(sqlproxy);

可以用這個

查看完整回答
反對 回復(fù) 2019-07-14
  • 4 回答
  • 0 關(guān)注
  • 1614 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號