本文整理汇总了C++中QTableView::show方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::show方法的具体用法?C++ QTableView::show怎么用?C++ QTableView::show使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::show方法的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: 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);
}
示例3: 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();
}
示例4: 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();
}
示例5: main
int main( int argc, char* argv[] ){
if(argc != 2){
return std::cerr<<"No!"<<std::endl;
}
QApplication a(argc,argv);
std::ifstream file;
file.open(argv[1]);
std::string line;
std::string alltext;
while(getline(file, line)){
alltext += line;
alltext += "\n";
}
file.close();
QString filetext(QString::fromStdString(alltext));
DnDAddressModel model(filetext);
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 a.exec();
}
示例6: 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();
}
示例7: 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();
}
示例8: showhistory
bool historymanager::showhistory()
{
tablemodel->select(); tablemodel->setHeaderData(1 , Qt::Horizontal ,tr("title"));
tablemodel->setHeaderData(2 , Qt::Horizontal , tr("url"));
QTableView * tableview = new QTableView();
tableview->setModel(tablemodel);
qDebug() << tablemodel->rowCount();
tableview->show();
}
示例9: createView
QTableView* createView(QSqlQueryModel *model)
{
QTableView *view = new QTableView;
view->setModel(model);
view->show();
return view;
}
示例10: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableView tableView;
MyModel myModel(0);
tableView.setModel( &myModel );
tableView.show();
return a.exec();
}
示例11: createView
void createView(const QString &title, QSqlQueryModel *model)
{
static int offset = 0;
QTableView *view = new QTableView;
view->setModel(model);
view->setWindowTitle(title);
view->move(100 + offset, 100 + offset);
offset += 20;
view->show();
}
示例12: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTableView tv;
QStandardItemModel m;
m.setRowCount(4);
m.setColumnCount(2);
tv.setModel(&m);
tv.show();
tv.setItemDelegate(new ExampleDelegate());
app.exec();
}
示例13: main
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QTableView* table = new QTableView();
TableModel* model = new TableModel(table);
MultipleSelectDelegate* delegate = new MultipleSelectDelegate(table);
table->setModel(model);
table->setItemDelegate(delegate);
table->show();
return app.exec();
}
示例14: createView
QTableView* createView(QSqlQueryModel *model, const QString &title = "")
{
QTableView *view = new QTableView;
view->setModel(model);
static int offset = 0;
view->setWindowTitle(title);
view->move(100 + offset, 100 + offset);
offset += 20;
view->show();
return view;
}
示例15: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTableView *qTableView = new QTableView;
MyModel myModel(0);
//setModel()
//1.告诉qTableView多少行多少列需要展示
//2.每个单元格需要展示什么内容,就是data()返回值
qTableView->setModel(&myModel);
qTableView->show();
return app.exec();
}