本文整理汇总了C++中QTableView::setSelectionModel方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::setSelectionModel方法的具体用法?C++ QTableView::setSelectionModel怎么用?C++ QTableView::setSelectionModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::setSelectionModel方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例3: createSongsTable
void MainWindow::createSongsTable(int size)
{
QTableView * songs = ui->tvSongs;
delete songs->model();
delete songs->selectionModel();
QStandardItemModel *model = new QStandardItemModel(size, 3, songs);
QItemSelectionModel *selections = new QItemSelectionModel(model);
songs->setModel(model);
songs->setSelectionModel(selections);
songs->horizontalHeader()->setSectionsMovable(true);
songs->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
songs->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
songs->verticalHeader()->setSectionsMovable(false);
songs->verticalHeader()->setVisible(false);
songs->setSelectionBehavior( QAbstractItemView::SelectRows );
songs->setSelectionMode( QAbstractItemView::SingleSelection );
songs->setContextMenuPolicy(Qt::CustomContextMenu);
// Set StaticContents to enable minimal repaints on resizes.
songs->viewport()->setAttribute(Qt::WA_StaticContents);
model->setHorizontalHeaderItem(0, new QStandardItem(tr("Artist")));
model->setHorizontalHeaderItem(1, new QStandardItem(tr("Title")));
model->setHorizontalHeaderItem(2, new QStandardItem(tr("Length")));
}
示例4: main
int main( int argc, char **argv )
{
QApplication app( argc, argv );
QTreeView *tree = new QTreeView();
QListView *list = new QListView();
QTableView *table = new QTableView();
QSplitter splitter;
splitter.addWidget(tree);
splitter.addWidget(list);
splitter.addWidget(table);
QStandardItemModel model( 5, 2 );
for( int r=0; r<5; r++ )
{
for( int c=0; c<2; c++)
{
QStandardItem *item = new QStandardItem(QString("Row:%0, Column:%1").arg(r).arg(c));
if(c == 0)
{
for(int i=0; i<3; i++)
{
QStandardItem *child = new QStandardItem(QString("Item %0").arg(i));
child->setEditable(false);
item->appendRow(child);
}
}
model.setItem(r, c, item);
}
}
model.setHorizontalHeaderItem(0, new QStandardItem("Foo"));
model.setHorizontalHeaderItem(1, new QStandardItem("Bar-Baz"));
tree->setModel(&model);
list->setModel(&model);
table->setModel(&model);
list->setSelectionModel(tree->selectionModel());
table->setSelectionModel(tree->selectionModel());
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setSelectionMode(QAbstractItemView::SingleSelection);
splitter.show();
MainWindow w;
w.show();
return app.exec();
}
示例5: main
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(interview);
QApplication app(argc, argv);
QSplitter page;
QAbstractItemModel *data = new Model(1000, 10, &page);
QItemSelectionModel *selections = new QItemSelectionModel(data);
QTableView *table = new QTableView;
table->setModel(data);
table->setSelectionModel(selections);
table->horizontalHeader()->setMovable(true);
table->verticalHeader()->setMovable(true);
// Set StaticContents to enable minimal repaints on resizes.
table->viewport()->setAttribute(Qt::WA_StaticContents);
page.addWidget(table);
QTreeView *tree = new QTreeView;
tree->setModel(data);
tree->setSelectionModel(selections);
tree->setUniformRowHeights(true);
tree->header()->setStretchLastSection(false);
tree->viewport()->setAttribute(Qt::WA_StaticContents);
// Disable the focus rect to get minimal repaints when scrolling on Mac.
tree->setAttribute(Qt::WA_MacShowFocusRect, false);
page.addWidget(tree);
QListView *list = new QListView;
list->setModel(data);
list->setSelectionModel(selections);
list->setViewMode(QListView::IconMode);
list->setSelectionMode(QAbstractItemView::ExtendedSelection);
list->setAlternatingRowColors(false);
list->viewport()->setAttribute(Qt::WA_StaticContents);
list->setAttribute(Qt::WA_MacShowFocusRect, false);
page.addWidget(list);
page.setWindowIcon(QPixmap(":/images/interview.png"));
page.setWindowTitle("Interview");
page.show();
return app.exec();
}
示例6: on_pbPosition_clicked
void SettingsDialog::on_pbPosition_clicked()
{
QScopedPointer< Gui::Dialog > dialog(new Gui::Dialog(Gui::Dialog::CenterOfScreen,this));
PositionModel *model = new PositionModel(dialog.data());
QTableView *view = new QTableView(dialog.data());
QItemSelectionModel *selectionModel = new QItemSelectionModel(model,dialog.data());
dialog->setWindowTitle(tr("Set position"));
QVBoxLayout *layout = new QVBoxLayout;
QDialogButtonBox *dialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal,dialog.data());
connect(dialogButtons,SIGNAL(accepted()),dialog.data(),SLOT(accept()));
connect(dialogButtons,SIGNAL(rejected()),dialog.data(),SLOT(reject()));
view->setModel(model);
view->setItemDelegateForColumn(0,new PositionLabelDelegate);
view->setItemDelegateForColumn(1,new PositionDelegate(QApplication::palette()));
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setSelectionModel(selectionModel);
view->verticalHeader()->setVisible(false);
view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
layout->addWidget(view);
layout->addWidget(dialogButtons);
dialog->setLayout(layout);
dialog->resize(700,500);
connect(dialog.data(),SIGNAL(executed()),view,SLOT(resizeColumnsToContents()));
connect(dialog.data(),SIGNAL(executed()),view,SLOT(resizeRowsToContents()));
selectionModel->select(model->index(pbPosition->property("wallPosition").toInt(),0),
QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
view->scrollTo(model->index(pbPosition->property("wallPosition").toInt(),0));
if (dialog->exec() == QDialog::Accepted)
{
Wally::Application::Position p = static_cast<Wally::Application::Position> (selectionModel->currentIndex().row());
pbPosition->setProperty("wallPosition",static_cast<int> (p));
pbPosition->setText(positionToString(p).replace("&","&&"));
settingsModified();
}
}
示例7: setupViews
void MainWindow::setupViews()
{
QSplitter *splitter = new QSplitter;
QTableView *table = new QTableView;
pieChart = new PieView;
splitter->addWidget(table);
splitter->addWidget(pieChart);
splitter->setStretchFactor(0, 0);
splitter->setStretchFactor(1, 1);
table->setModel(model);
pieChart->setModel(model);
QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
table->setSelectionModel(selectionModel);
pieChart->setSelectionModel(selectionModel);
QHeaderView *headerView = table->horizontalHeader();
headerView->setStretchLastSection(true);
setCentralWidget(splitter);
}
示例8: setupView
void MainWindow::setupView()
{
QSplitter *splitter = new QSplitter;
splitter->setOrientation(Qt::Vertical);
QTableView *table = new QTableView;
HistogramView *histogram = new HistogramView(splitter);
table->setModel(model);
histogram->setModel(model);
QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
table->setSelectionModel(selectionModel);
histogram->setSelectionModel(selectionModel);
connect(selectionModel,SIGNAL(selectionChanged(const QItemSelection, const QItemSelection)),
histogram,SLOT(selectionChanged(const QItemSelection, const QItemSelection)));
connect(selectionModel,SIGNAL(selectionChanged(const QItemSelection, const QItemSelection)),
table,SLOT(selectionChanged(const QItemSelection, const QItemSelection)));
splitter->addWidget(table);
splitter->addWidget(histogram);
setCentralWidget(splitter);
}