本文整理汇总了C++中QTableView::resizeColumnsToContents方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::resizeColumnsToContents方法的具体用法?C++ QTableView::resizeColumnsToContents怎么用?C++ QTableView::resizeColumnsToContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::resizeColumnsToContents方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: MakeTableView
// Table factory
QTableView* MakeTableView(QAbstractItemModel* model, bool sortingEnabled = true, uint32_t modelSortColumn = 0)
{
class MyTable : public QTableView
{
public:
QStyleOptionViewItem viewOptions() const override
{
QStyleOptionViewItem option = QTableView::viewOptions();
option.decorationAlignment = Qt::AlignHCenter | Qt::AlignCenter;
option.decorationPosition = QStyleOptionViewItem::Top;
return option;
}
void mouseMoveEvent(QMouseEvent* event) override
{
QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
QVariant data = model()->data(index, PlayerTableModel::CursorRole);
Qt::CursorShape shape = Qt::ArrowCursor;
if (!data.isNull()) {
shape = Qt::CursorShape(data.toInt());
}
setCursor(shape);
}
QTableView::mouseMoveEvent(event);
}
};
QTableView* tableView = new MyTable();
tableView->setModel(model);
tableView->setSortingEnabled(sortingEnabled);
if (sortingEnabled) {
tableView->sortByColumn(FindColumn(model, modelSortColumn));
}
tableView->verticalHeader()->hide();
tableView->setAlternatingRowColors(true);
tableView->verticalHeader()->setDefaultSectionSize(15);
tableView->resizeColumnsToContents();
tableView->horizontalHeader()->setStretchLastSection(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
tableView->setFocusPolicy(Qt::StrongFocus);
// enable mouse tracking
tableView->setMouseTracking(true);
tableView->viewport()->setMouseTracking(true);
tableView->installEventFilter(this);
tableView->viewport()->installEventFilter(this);
return tableView;
}
示例3: setupUI
void LoungeWidget::setupUI()
{
QVBoxLayout *mainLayout = new QVBoxLayout();
QTableView *connected = new QTableView();
mainLayout->addWidget(connected);
connected->setModel(m_connectedPlayerList);
connected->setSortingEnabled(true);
connected->resizeColumnsToContents();
connected->horizontalHeader()->setStretchLastSection(true);
connected->sortByColumn(0, Qt::AscendingOrder);
connect(connected, SIGNAL(activated(QModelIndex)), this, SLOT(processActivatedRow(QModelIndex)));
setLayout(mainLayout);
}
示例4: createView
QTableView* createView(QSqlQueryModel *model, const QString &title = "")
{
QTableView *view = new QTableView;
view->setModel(model);
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
Q_UNUSED(title);
view->resizeColumnsToContents();
#else
static int offset = 0;
view->setWindowTitle(title);
view->move(100 + offset, 100 + offset);
offset += 20;
view->show();
#endif
return view;
}
示例5: QWidget
//! [0]
TableEditor::TableEditor(const QString &tableName, QWidget *parent)
: QWidget(parent)
{
model = new QSqlTableModel(this);
model->setTable(tableName);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("ID"));
model->setHeaderData(1, Qt::Horizontal, tr("First name"));
model->setHeaderData(2, Qt::Horizontal, tr("Last name"));
//! [0] //! [1]
QTableView *view = new QTableView;
view->setModel(model);
view->resizeColumnsToContents();
//! [1]
//! [2]
submitButton = new QPushButton(tr("Submit"));
submitButton->setDefault(true);
revertButton = new QPushButton(tr("&Revert"));
quitButton = new QPushButton(tr("Quit"));
buttonBox = new QDialogButtonBox(Qt::Vertical);
buttonBox->addButton(submitButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(revertButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
//! [2]
//! [3]
connect(submitButton, SIGNAL(clicked()), this, SLOT(submit()));
connect(revertButton, SIGNAL(clicked()), model, SLOT(revertAll()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
//! [3]
//! [4]
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(view);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Cached Table"));
}
示例6: QWidget
TableView::TableView()
: QWidget()
{
if (! this->createConnection()) {
QString msg = "** Create Database Error";
throw msg;
}
setWindowTitle(tr("Table View Model"));
setMinimumSize(300, 350);
//
QSqlTableModel *model = new QSqlTableModel(this, m_db);
QStringList tempX = m_db.tables();
model->setTable(tempX.at(0));
QSqlError error = model->lastError();
if ( error.isValid() ) {
ksMsg( this, "Table View - SQL Error", error.text() );
}
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setSort(2, Qt::AscendingOrder);
model->select();
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
//
QTableView *view = new QTableView;
view->setModel(model);
view->resizeColumnsToContents();
QHeaderView *temp = view->horizontalHeader();
temp->setStretchLastSection(true);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(view);
setLayout(mainLayout);
}
示例7: 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&)));
}
}
示例8: 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();
}
示例9: 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
}
示例10: getSpeciesList
bool DatabaseHandler::getSpeciesList(QString type, QComboBox * cmb_box) {
qDebug() << "Populating species list for " << type;
QString qstr = "SELECT name_de, name_lat, euring_id, length FROM taxa LEFT JOIN "
"(SELECT id_code, to_char(avg(length), 'FM99.99') as length FROM census WHERE tp='%1' GROUP BY id_code) as lt ON taxa.euring_id = lt.id_code "
"WHERE type='%1' ORDER BY seaflag DESC, name_de";
QSqlQueryModel * model = new QSqlQueryModel;
model->setQuery(qstr.arg(type));
qDebug() << qstr.arg(type);
model->setHeaderData(0, Qt::Horizontal, "Deutscher Name");
model->setHeaderData(1, Qt::Horizontal, "Wissenschaftlicher Name");
model->setHeaderData(2, Qt::Horizontal, "EURING Code");
model->setHeaderData(3, Qt::Horizontal, QString::fromUtf8("Länge"));
cmb_box->setModel(model);
QTableView * view = new QTableView;
cmb_box->setView(view);
view->verticalHeader()->hide();
view->hideColumn(2);
view->resizeColumnsToContents();
view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->setMinimumWidth(view->horizontalHeader()->length());
return true;
}
示例11: 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;
}
示例12: 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();
}