MainWindow::MainWindow() { QSpreadsheetHeaderView *hv = new QSpreadsheetHeaderView(Qt::Horizontal, this); hv->setClickable(true); hv->setHighlightSections(true); TableModel *model = new TableModel(this); QTableView *tv = new QTableView(this); tv->setModel(model); tv->setHorizontalHeader(hv); setCentralWidget(tv); }
void CCustomHeadersTest::test_insertRowColumn_1() { QTableView stTableView; m_ptrShopHeader = new CShopHeaderView(); stTableView.setHorizontalHeader(m_ptrShopHeader); stTableView.setModel(m_ptrModel); stTableView.show(); ////////////////////////////////////////////////////////////////////////// QCOMPARE(m_ptrModel->columnCount(),1); QCOMPARE(m_ptrModel->rowCount(),1); int iColumnCount = m_ptrModel->columnCount(); QVERIFY(m_ptrModel->insertColumn(iColumnCount)); QVERIFY(m_ptrModel->insertRow(m_ptrModel->rowCount())); m_ptrModel->setHeaderData(iColumnCount,Qt::Horizontal,true,Role_ShopColumnActive); QVERIFY(m_ptrModel->insertColumn(m_ptrModel->columnCount())); QVERIFY(m_ptrModel->insertRow(m_ptrModel->rowCount())); }
//----------------------------------------------------------------------------- int ctkCheckableHeaderViewTest1(int argc, char * argv [] ) { QApplication app(argc, argv); #if 0 QFileSystemModel model; model.setRootPath(QDir::currentPath()); #else QStandardItemModel model; QStandardItem item; item.insertColumns(0, 5); item.insertRows(0, 7); model.insertRow(0, &item); #endif QTableView table; table.setModel(&model); model.setHeaderData(0, Qt::Horizontal, Qt::Checked, Qt::CheckStateRole); QHeaderView* previousHeaderView = table.horizontalHeader(); ctkCheckableHeaderView* headerView = new ctkCheckableHeaderView(Qt::Horizontal, &table); qDebug() << previousHeaderView->isClickable(); headerView->setClickable(previousHeaderView->isClickable()); headerView->setMovable(previousHeaderView->isMovable()); headerView->setHighlightSections(previousHeaderView->highlightSections()); headerView->setPropagateToItems(true); table.setHorizontalHeader(headerView); qDebug() << headerView->isCheckable(0); table.show(); table.raise(); //app.exec(); return EXIT_SUCCESS; }