本文整理汇总了C++中QTableView::resizeRowsToContents方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::resizeRowsToContents方法的具体用法?C++ QTableView::resizeRowsToContents怎么用?C++ QTableView::resizeRowsToContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::resizeRowsToContents方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: ModelToView
void GuiTools::ModelToView(QAbstractItemModel *model, QAbstractItemView *view)
{
view->reset();
view->setModel(model);
QTableView* tableView = dynamic_cast<QTableView*>(view);
if(tableView && model)
{
tableView->horizontalHeader()->setStretchLastSection(true);
tableView->resizeColumnsToContents();
tableView->resizeRowsToContents();
// // set maximum height
// int count = model->rowCount(QModelIndex());
// int h=0;
// for (int i = 0; i < count; i++)
// h += tableView->rowHeight(i);
// int maxH =
// (h + // total row height
// count + // to account for the pixel(s) used in the grid
// tableView->horizontalHeader()->height() +
// tableView->horizontalScrollBar()->height()); // Need room for the horizontal scrollbar
// tableView->setMaximumHeight(maxH);
// tableView->resize(tableView->width(),maxH);
}
QTreeView* treeView = dynamic_cast<QTreeView*>(view);
if(treeView && model)
{
for(int i=0;i<model->columnCount();i++)
treeView->resizeColumnToContents(i);
treeView->setSortingEnabled(true);
}
MyTreeView* myTreeView = dynamic_cast<MyTreeView*>(view);
if(myTreeView && model)
{
connect(model,SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)),myTreeView,SLOT(onDataChanged(const QModelIndex&,const QModelIndex&)));
}
}
示例3: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//QListView view;
QTableView view;
view.setSortingEnabled(false);
view.horizontalHeader()->setStretchLastSection(true);
view.horizontalHeader()->setVisible(false);
view.verticalHeader()->setVisible(false);
MillionRows model(Q_NULLPTR);
view.setModel(&model);
view.setAlternatingRowColors(true);
view.setStyleSheet("alternate-background-color: green;background-color: white;");
view.setItemDelegateForColumn(0, new TableStyleDelegate());
view.resizeRowsToContents(); // impact performance - force call sizeHint
view.show();
return a.exec();
}
示例4: on_actShowStat_triggered
void MainWindow::on_actShowStat_triggered()
{
QString query = QString("call p_showStat_admin('%1', '%2', 0);")
.arg(_model->dateA_dbformat())
.arg(_model->dateZ_dbformat());
qDebug() << query;
QSqlQueryModel *m = App::theApp()->db_model(query);
QDialog *dlgStat = new QDialog();
dlgStat->setWindowTitle("Статистика");
dlgStat->setGeometry(200, 200, 400, 200);
QTableView* view = new QTableView();
view->setModel(m);
view->resizeColumnsToContents();
view->resizeRowsToContents();
QVBoxLayout* lay = new QVBoxLayout(dlgStat);
lay->addWidget(view);
dlgStat->exec();
}
示例5: createLayout
void DkFileAssociationsPreference::createLayout() {
QStringList fileFilters = Settings::param().app().openFilters;
mModel = new QStandardItemModel(this);
mModel->setObjectName("fileModel");
for (int rIdx = 1; rIdx < fileFilters.size(); rIdx++)
mModel->appendRow(getItems(fileFilters.at(rIdx), checkFilter(fileFilters.at(rIdx), Settings::param().app().browseFilters), checkFilter(fileFilters.at(rIdx), Settings::param().app().registerFilters)));
mModel->setHeaderData(0, Qt::Horizontal, tr("Filter"));
mModel->setHeaderData(1, Qt::Horizontal, tr("Browse"));
mModel->setHeaderData(2, Qt::Horizontal, tr("Register"));
QTableView* filterTableView = new QTableView(this);
filterTableView->setModel(mModel);
filterTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
filterTableView->verticalHeader()->hide();
//filterTableView->horizontalHeader()->hide();
filterTableView->setShowGrid(false);
filterTableView->resizeColumnsToContents();
filterTableView->resizeRowsToContents();
filterTableView->setWordWrap(false);
QPushButton* openDefault = new QPushButton(tr("Set as Default Viewer"), this);
openDefault->setObjectName("openDefault");
// now the final widgets
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(filterTableView);
#ifdef Q_OS_WIN
layout->addWidget(openDefault);
#else
openDefault->hide();
#endif
}
示例6: QSortFilterProxyModel
QSortFilterProxyModel * GuiTools::ModelToViewWithFilter(QAbstractItemModel *model, QAbstractItemView *view,QLineEdit* lineEdit,QSortFilterProxyModel *proxyModel)
{
view->reset();
if(!proxyModel)
proxyModel = new QSortFilterProxyModel((QObject*)lineEdit);
proxyModel->setSourceModel(model);
view->setModel(proxyModel);
//view->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
QTableView* tableView = dynamic_cast<QTableView*>(view);
if(tableView)
{
tableView->horizontalHeader()->setStretchLastSection(true);
tableView->resizeColumnsToContents();
tableView->resizeRowsToContents();
tableView->setSortingEnabled(true);
tableView->verticalHeader()->hide();
}
QTreeView* treeView = dynamic_cast<QTreeView*>(view);
if(treeView)
{
for(int i=0;i<model->columnCount();i++)
treeView->resizeColumnToContents(i);
treeView->setSortingEnabled(true);
}
// views' filter
proxyModel->setFilterKeyColumn(0);
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
connect(lineEdit,SIGNAL(textChanged(const QString&)),
proxyModel,SLOT(setFilterWildcard(const QString&)),Qt::AutoConnection);
return proxyModel;
}
示例7: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// ![0]
QStandardItemModel model(0, 1);
populateListModel(&model);
// ![0]
QWidget toplevel;
QVBoxLayout *layout = new QVBoxLayout(&toplevel);
// ![1]
QMaemo5ValueButton *button1 = new QMaemo5ValueButton("Value besides text");
button1->setValueLayout(QMaemo5ValueButton::ValueBesideText);
QMaemo5ListPickSelector *selector1 = new QMaemo5ListPickSelector;
selector1->setModel(&model);
// not setting the current index means that the value is empty.
button1->setPickSelector(selector1);
// ![1]
// ![2]
QStandardItemModel tableModel(0, 0);
populateTableModel(&tableModel);
// ![2]
// ![3]
QMaemo5ValueButton *button2 = new QMaemo5ValueButton("Value under text");
button2->setValueLayout(QMaemo5ValueButton::ValueUnderText);
QMaemo5ListPickSelector *selector2 = new QMaemo5ListPickSelector;
selector2->setModel(&tableModel);
selector2->setModelColumn(2);
selector2->setCurrentIndex(5);
button2->setPickSelector(selector2);
// ![3]
// create a custom view we want a table view instead of a list
QTableView *view = new QTableView();
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
// try to get a sensible column width and row height
view->setModel(&tableModel); // set the model in order to get correct column widths
view->resizeColumnsToContents();
view->resizeRowsToContents();
view->horizontalHeader()->setStretchLastSection(true);
view->verticalHeader()->setVisible(false);
view->horizontalHeader()->setVisible(false);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->setSelectionMode(QAbstractItemView::SingleSelection);
// five rows should be visible as a default
if (view->verticalHeader()->sectionSize(0)>0)
view->setMinimumHeight(view->verticalHeader()->sectionSize(0) * 5);
QMaemo5ValueButton *button3 = new QMaemo5ValueButton("Value centered under text");
button3->setValueLayout(QMaemo5ValueButton::ValueUnderTextCentered);
QMaemo5ListPickSelector *selector3 = new QMaemo5ListPickSelector;
selector3->setModel(&tableModel);
selector3->setModelColumn(2);
selector3->setView(view); // set our new custom view
selector3->setCurrentIndex(0);
button3->setPickSelector(selector3);
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
toplevel.show();
return app.exec();
}