本文整理汇总了C++中QTableView::setModel方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::setModel方法的具体用法?C++ QTableView::setModel怎么用?C++ QTableView::setModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::setModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TableModel *model = new TableModel(4, 2, &app);
//! [0]
QTableView *firstTableView = new QTableView;
QTableView *secondTableView = new QTableView;
//! [0]
//! [1]
firstTableView->setModel(model);
secondTableView->setModel(model);
//! [1]
firstTableView->horizontalHeader()->setModel(model);
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
QModelIndex index = model->index(row, column, QModelIndex());
model->setData(index, QVariant(QString("(%1, %2)").arg(row).arg(column)));
}
}
//! [2]
secondTableView->setSelectionModel(firstTableView->selectionModel());
//! [2]
firstTableView->setWindowTitle("First table view");
secondTableView->setWindowTitle("Second table view");
firstTableView->show();
secondTableView->show();
return app.exec();
}
示例2: loadTables
void UserForm:: loadTables()
{
createTableModels();
QTableView* productsView = ui->tableView;
productsView->setModel(productsModel);
productsView->setColumnHidden(0, true);
QTableView* ordersView = ui->tableViewOrders;
ordersView->setModel(ordersModel);
}
示例3: createTable
/*!
Create and return the table used to visualize digital signals.
*/
QTableView* UiDigitalGenerator::createTable()
{
// Deallocation: "Qt Object trees" (See UiMainWindow)
QTableView* table = new QTableView(this);
QItemSelectionModel* m = table->selectionModel();
if (m != NULL) delete m;
table->setModel(mSignals);
// Deallocation: "Qt Object trees" (See UiMainWindow)
DigitalDelegate* delegate = new DigitalDelegate(this);
QAbstractItemDelegate* d = table->itemDelegate();
if (d != NULL) delete d;
table->setItemDelegate(delegate);
table->resizeColumnsToContents();
table->resizeRowsToContents();
connect(table->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this,
SLOT(handleSelectionChanged(QItemSelection,QItemSelection)));
return table;
}
示例4: loadNetwork
void MainWindow::loadNetwork()
{
setWindowTitle("Qt-dtnet - " + ws.networkFilename);
delete networkToolBox;
networkToolBox = new QToolBox();
ui->dockProperties->setWidget(networkToolBox);
QTableView *propertiesTree;
std::map<std::string,Population>::iterator i;
for (i = ws.net->populations.begin(); i != ws.net->populations.end(); ++i)
{
propertiesTree = new QTableView();
propertiesTree->setAlternatingRowColors(false);
propertiesTree->setSelectionBehavior( QAbstractItemView::SelectRows );
propertiesTree->setWordWrap( false );
// propertiesTree->setAnimated( false );
networkToolBox->addItem(propertiesTree, QString::fromStdString(i->first));
propertiesModel = new PropModel( &(i->second) );
propertiesTree->setModel(propertiesModel);
}
networkView->replaceNetwork( ws.net );
networkView->show();
if ( ws.trial->isReady() && ws.net->isReady() ) ui->actionRun_Simulation->setEnabled( true );
}
示例5: main
int main(int argc, char *argv[])
{
std::cout << "Enter." << std::endl;
QApplication app(argc, argv);
QStandardItemModel model(4, 2);
QTableView tableView;
tableView.setModel(&model);
ComboBoxDelegate delegate;
//tableView.setItemDelegate(&delegate);
tableView.setItemDelegateForColumn(1, &delegate); // Column 0 can take any value, column 1 can only take values up to 8.
//tableView.horizontalHeader()->setStretchLastSection(true);
for (int row = 0; row < 4; ++row)
{
for (int column = 0; column < 2; ++column)
{
QModelIndex index = model.index(row, column, QModelIndex());
model.setData(index, QVariant((row+1) * (column+1)));
}
}
tableView.show();
return app.exec();
}
示例6: main
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QFrame frame;
QVBoxLayout verticalLayout;
QLineEdit filterText;
ProblemsTableModel submissions;
// add data here
QSortFilterProxyModel proxy;
proxy.setSortCaseSensitivity(Qt::CaseInsensitive);
proxy.setFilterCaseSensitivity(Qt::CaseInsensitive);
proxy.setSourceModel(&submissions);
// sort and filter by "Full name" column
proxy.setFilterKeyColumn(2);
QTableView tableView;
tableView.setModel(&proxy);
tableView.setSortingEnabled(true);
verticalLayout.addWidget(&filterText);
verticalLayout.addWidget(&tableView);
frame.setLayout(&verticalLayout);
QObject::connect(&filterText, &QLineEdit::textChanged, &proxy, &QSortFilterProxyModel::setFilterFixedString);
frame.show();
return app.exec();
}
示例7: QWidget
ErrorListView::ErrorListView(QWidget* parent)
: QWidget(parent),
m_model(0)
{
m_model = new ErrorListModel(this);
QTableView* tableView = new QTableView;
tableView->setItemDelegate(new ItemDelegate);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setAlternatingRowColors(true);
tableView->setShowGrid(false);
tableView->verticalHeader()->hide();
tableView->setModel(m_model);
#ifdef STROMX_STUDIO_QT4
tableView->horizontalHeader()->setResizeMode(ErrorListModel::TIME, QHeaderView::Interactive);
tableView->horizontalHeader()->setResizeMode(ErrorListModel::DESCRIPTION, QHeaderView::Stretch);
#else
tableView->horizontalHeader()->setSectionResizeMode(ErrorListModel::TIME, QHeaderView::Interactive);
tableView->horizontalHeader()->setSectionResizeMode(ErrorListModel::DESCRIPTION, QHeaderView::Stretch);
#endif // STROMX_STUDIO_QT4
QPushButton* clearButton = new QPushButton(tr("Clear error log"));
connect(clearButton, SIGNAL(clicked()), m_model, SLOT(clear()));
QHBoxLayout* buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(clearButton);
buttonLayout->addStretch();
QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addWidget(tableView);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
}
示例8: main
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
// Open the addressbook file in the working directory
QFile file("addressbook.csv");
if ( !file.open(QIODevice::ReadOnly|QIODevice::Text) )
return 1;
// Read its content into a string
QString addresses = QString::fromUtf8(file.readAll());
AddressbookModel model(addresses);
QListView listView;
listView.setModel(&model);
listView.setModelColumn(0);
listView.show();
QTreeView treeView;
treeView.setModel(&model);
treeView.show();
QTableView tableView;
tableView.setModel(&model);
tableView.show();
return app.exec();
}
示例9: model
void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck()
{
QStandardItemModel model(3, 1);
for (int i = 0; i < 3; ++i) {
QStandardItem *item = new QStandardItem(QLatin1String("Item ") + QString::number(i));
item->setCheckable(true);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
model.setItem(i, item);
}
QTableView view;
view.setModel(&model);
view.setItemDelegate(new TestItemDelegate);
view.show();
view.selectAll();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QStyleOptionViewItem option;
option.rect = view.visualRect(model.index(0, 0));
// mimic QStyledItemDelegate::initStyleOption logic
option.features = QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasCheckIndicator;
option.checkState = Qt::CheckState(model.index(0, 0).data(Qt::CheckStateRole).toInt());
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
QPoint pos = qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center()
+ QPoint(checkMargin, 0);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pos);
QTRY_VERIFY(view.selectionModel()->isColumnSelected(0, QModelIndex()));
QCOMPARE(model.item(0)->checkState(), Qt::Checked);
}
示例10: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDirModel model;
QTreeView tree;
QListView list;
QTableView table;
tree.setModel(&model);
list.setModel(&model);
table.setModel(&model);
tree.setSelectionMode(QAbstractItemView::MultiSelection);
list.setSelectionModel(tree.selectionModel());
table.setSelectionModel(tree.selectionModel());
QObject::connect(&tree,SIGNAL(doubleClicked(QModelIndex)),&list,SLOT(setRootIndex(QModelIndex)));
QObject::connect(&tree,SIGNAL(doubleClicked(QModelIndex)),&table,SLOT(setRootIndex(QModelIndex)));
QSplitter *splitter = new QSplitter;
splitter->addWidget(&tree);
splitter->addWidget(&list);
splitter->addWidget(&table);
splitter->setWindowTitle(QObject::tr("Model/View"));
splitter->show();
return a.exec();
}
示例11: main
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );
db.setDatabaseName( "testdatabase.db" );
if( !db.open() )
{
qDebug() << db.lastError();
qFatal( "Failed to connect." );
}
QSqlQuery qry;
qry.prepare( "CREATE TABLE IF NOT EXISTS names (id INTEGER UNIQUE PRIMARY KEY, "
"firstname VARCHAR(30), "
"lastname VARCHAR(30))" );
if( !qry.exec() )
{
qDebug() << qry.lastError();
qFatal( "Failed to create the table" );
}
qry.prepare( "INSERT INTO names (id, firstname, lastname) "
"VALUES (:id, :firstname, :lastname)" );
qry.bindValue( ":id", 1 );
qry.bindValue( ":firstname", "John" );
qry.bindValue( ":lastname", "Doe" );
if( !qry.exec() )
{
qDebug() << qry.lastError();
qFatal( "Failed to insert" );
}
QSqlTableModel *model = new QSqlTableModel();
model->setTable( "names" );
model->setFilter( "lastname = 'Doe'" );
model->select();
// if removeColumn is enabled, the table won't be editable, this
// is a bug under this old version
//model->removeColumn( 0 );
QTableView *view = new QTableView();
//view->setColumnHidden( 0, true );
view->setModel( model );
view->show();
/*
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery( "SELECT firstname, lastname FROM names" );
QTableView *view = new QTableView();
view->setModel( model );
view->show();
*/
return app.exec();
}
示例12: main
//! [0]
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStandardItemModel model(4, 2);
QTableView tableView;
tableView.setModel(&model);
SpinBoxDelegate delegate;
tableView.setItemDelegate(&delegate);
//! [0]
tableView.horizontalHeader()->setStretchLastSection(true);
//! [1]
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
QModelIndex index = model.index(row, column, QModelIndex());
model.setData(index, QVariant((row+1) * (column+1)));
}
//! [1] //! [2]
}
//! [2]
//! [3]
tableView.setWindowTitle(QObject::tr("Spin Box Delegate"));
tableView.show();
return app.exec();
}
示例13: setupTabs
void AddressWidget::setupTabs()
{
QStringList groups;
groups << "ABC" << "DEF" << "GHI" << "JKL" << "MNO" << "PQR" << "STU" << "VW" << "XYZ";
for (int i = 0; i < groups.size(); ++i) {
QString str = groups.at(i);
proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(table);
proxyModel->setDynamicSortFilter(true);
QTableView *tableView = new QTableView;
tableView->setModel(proxyModel);
tableView->setSortingEnabled(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->horizontalHeader()->setStretchLastSection(true);
tableView->verticalHeader()->hide();
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
QString newStr = QString("^[%1].*").arg(str);
proxyModel->setFilterRegExp(QRegExp(newStr, Qt::CaseInsensitive));
proxyModel->setFilterKeyColumn(0);
proxyModel->sort(0, Qt::AscendingOrder);
connect(tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SIGNAL(selectionChanged(QItemSelection)));
addTab(tableView, str);
}
}
示例14: setModel
void ReceiveCoinsDialog::setModel(WalletModel *_model)
{
this->model = _model;
if(_model && _model->getOptionsModel())
{
_model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
updateDisplayUnit();
QTableView* tableView = ui->recentRequestsView;
tableView->verticalHeader()->hide();
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
tableView->setModel(_model->getRecentRequestsTableModel());
tableView->setAlternatingRowColors(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
tableView->setColumnWidth(RecentRequestsTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
connect(tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
// Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this);
}
示例15: editKernel
void ConvolveMatrixEffectConfigWidget::editKernel()
{
if (!m_effect) {
return;
}
QVector<qreal> oldKernel = m_effect->kernel();
QPoint kernelSize = m_effect->order();
m_matrixModel->setMatrix(oldKernel, kernelSize.y(), kernelSize.x());
connect(m_matrixModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(kernelChanged()));
QPointer<QDialog> dlg = new QDialog(this);
QTableView *table = new QTableView(dlg);
table->setModel(m_matrixModel);
table->horizontalHeader()->hide();
table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
table->verticalHeader()->hide();
table->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
QVBoxLayout *mainLayout = new QVBoxLayout;
dlg->setLayout(mainLayout);
mainLayout->addWidget(table);
if (dlg->exec() == QDialog::Accepted) {
m_effect->setKernel(m_matrixModel->matrix());
emit filterChanged();
} else {
m_effect->setKernel(oldKernel);
}
delete dlg;
disconnect(m_matrixModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(kernelChanged()));
}