本文整理汇总了C++中QTreeView::resizeColumnToContents方法的典型用法代码示例。如果您正苦于以下问题:C++ QTreeView::resizeColumnToContents方法的具体用法?C++ QTreeView::resizeColumnToContents怎么用?C++ QTreeView::resizeColumnToContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTreeView
的用法示例。
在下文中一共展示了QTreeView::resizeColumnToContents方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QWidget
QWidget * StitcherWorkspace::createConstraintsTree() {
QWidget * top = new QWidget(this);
QVBoxLayout * vbox = new QVBoxLayout(top);
top->setContentsMargins(0,0,0,0);
vbox->setContentsMargins(0,0,0,0);
/* need a real QTreeView with a model */
QStandardItemModel * model = new QStandardItemModel;
QTreeView *treeView = new QTreeView(top);
vbox->addWidget(treeView);
constraintsTree = treeView;
treeView->setModel(model);
initConstraintsTree();
treeView->setAlternatingRowColors(true);
treeView->setSelectionMode(QAbstractItemView::SingleSelection);
treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
treeView->resizeColumnToContents(0);
treeView->resizeColumnToContents(1);
QHBoxLayout * hbox = new QHBoxLayout();
QPushButton * addConstraint = new QPushButton("Add Constraint",top);
QPushButton * delConstraint = new QPushButton("Del Constraint",top);
connect(addConstraint,SIGNAL(clicked()),this,SLOT(onAddConstraintClicked()));
connect(delConstraint,SIGNAL(clicked()),this,SLOT(onDelConstraintClicked()));
hbox->addWidget(addConstraint);
hbox->addWidget(delConstraint);
vbox->addLayout(hbox);
QPushButton * optimizeGeometry = new QPushButton("Optimize Geometry",top);
connect(optimizeGeometry,SIGNAL(clicked()),this,SLOT(onOptimizeGeometryClicked()));
vbox->addWidget(optimizeGeometry);
return top;
}
示例2: QDialog
DirectoryTree::DirectoryTree(const QString &dir, QWidget *parent) : QDialog(parent)
{
QTreeView *view = new QTreeView(this);
QDirModel *model = new QDirModel;
view->setModel(model);
view->setRootIndex(model->index(dir));
view->resizeColumnToContents(0);
setWindowTitle(dir);
QPushButton *ok = new QPushButton(tr("&OK"));
QSpacerItem *item = new QSpacerItem(40, 20, QSizePolicy::Expanding);
QHBoxLayout *bottom = new QHBoxLayout;
bottom->addItem(item);
bottom->addWidget(ok);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(view);
layout->addLayout(bottom);
setLayout(layout);
setMinimumSize(600, 400);
// resize(sizeHint());
ok->setFocus();
connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
}
示例3: QDialog
OpenGL::OpenGL (QWidget* parent, const GL::Format& format) : QDialog (parent)
{
TreeModel* model = new TreeModel (this);
TreeItem* root = model->rootItem;
GLint i;
gl::GetIntegerv (gl::MAJOR_VERSION, &i);
std::string text = str(i) + ".";
gl::GetIntegerv (gl::MINOR_VERSION, &i);
text += str(i);
root->appendChild (new TreeItem ("API version", text, root));
root->appendChild (new TreeItem ("Renderer", (const char*) gl::GetString (gl::RENDERER), root));
root->appendChild (new TreeItem ("Vendor", (const char*) gl::GetString (gl::VENDOR), root));
root->appendChild (new TreeItem ("Version", (const char*) gl::GetString (gl::VERSION), root));
TreeItem* bit_depths = new TreeItem ("Bit depths", std::string(), root);
root->appendChild (bit_depths);
bit_depths->appendChild (new TreeItem ("red", str (format.redBufferSize()), bit_depths));
bit_depths->appendChild (new TreeItem ("green", str (format.greenBufferSize()), bit_depths));
bit_depths->appendChild (new TreeItem ("blue", str (format.blueBufferSize()), bit_depths));
bit_depths->appendChild (new TreeItem ("alpha", str (format.alphaBufferSize()), bit_depths));
bit_depths->appendChild (new TreeItem ("depth", str (format.depthBufferSize()), bit_depths));
bit_depths->appendChild (new TreeItem ("stencil", str (format.stencilBufferSize()), bit_depths));
#if QT_VERSION >= 0x050400
root->appendChild (new TreeItem ("Buffering", format.swapBehavior() == QSurfaceFormat::SingleBuffer ? "single" :
( format.swapBehavior() == QSurfaceFormat::DoubleBuffer ? "double" : "triple" ), root));
#else
root->appendChild (new TreeItem ("Buffering", format.doubleBuffer() ? "double" : "single", root));
#endif
root->appendChild (new TreeItem ("VSync", format.swapInterval() ? "on" : "off", root));
root->appendChild (new TreeItem ("Multisample anti-aliasing", format.samples() ? str(format.samples()).c_str() : "off", root));
gl::GetIntegerv (gl::MAX_TEXTURE_SIZE, &i);
root->appendChild (new TreeItem ("Maximum texture size", str (i), root));
QTreeView* view = new QTreeView;
view->setModel (model);
view->resizeColumnToContents (0);
view->resizeColumnToContents (1);
view->setMinimumSize (500, 200);
QDialogButtonBox* buttonBox = new QDialogButtonBox (QDialogButtonBox::Ok);
connect (buttonBox, SIGNAL (accepted()), this, SLOT (accept()));
QVBoxLayout* layout = new QVBoxLayout (this);
layout->addWidget (view);
layout->addWidget (buttonBox);
setLayout (layout);
setWindowTitle (tr ("OpenGL information"));
setSizeGripEnabled (true);
adjustSize();
}
示例4: expandTreeView
void SatellitesConfigDialog::expandTreeView()
{
QTreeView *treeView = m_configWidget->treeView;
if( !treeView->model() ) {
return;
}
// expand only branches with selected items
treeView->expandAll();
for ( int i = 0; i < treeView->model()->columnCount(); ++i ) {
treeView->resizeColumnToContents( i );
}
}
示例5: QTreeView
QTreeView * StitcherWorkspace::createGeometryTree() {
/* need a real QTreeView with a model */
QStandardItemModel * model = new QStandardItemModel;
QTreeView *treeView = new QTreeView(this);
geometryTree = treeView;
treeView->setModel(model);
loadGeometry();
treeView->setAlternatingRowColors(true);
treeView->setSelectionMode(QAbstractItemView::SingleSelection);
treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
treeView->resizeColumnToContents(0);
treeView->resizeColumnToContents(1);
connect(model,SIGNAL(itemChanged(QStandardItem * )),this,SLOT(onItemChanged(QStandardItem *)));
return treeView;
}
示例6: 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&)));
}
}
示例7: 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;
}
示例8: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget * main_wg = new QWidget;
// cria um objeto "splitter" para compartilhar widgets:
QSplitter *splitter = new QSplitter(main_wg);
// cria um "model" usando o "StandardModel"
QStandardItemModel *model = new QStandardItemModel;
const int totCols = 3;
int col;
// define os títulos das colunas:
for (col = 0; col < totCols; ++col)
{
model->setHorizontalHeaderItem(col,
new QStandardItem( QString("COL-%1").arg(col+1) ) );
}
// alimenta linhas, colunas e sub-níveis:
QStandardItem *parentItem = model->invisibleRootItem();
const int iniLevel = 0;
const int totLevels= 3;
QString prevRows("");
QVector<QSize> vec_ColsRows; // colunas, linhas de cada nível
vec_ColsRows.reserve( totLevels );
// quantidade-colunas, quantidade-linhas
vec_ColsRows << QSize(3,10) << QSize(3,3) << QSize(3,2) ;
populate_model ( parentItem, vec_ColsRows,
iniLevel, prevRows);
// Neste exemplo,
// O "model" foi alimentado com linhas, colunas e sub-níveis:
// E serão criadas 4 "views" (uma "tree", uma "table", uma "list" e uma "comboBox")
// relacionadas ao mesmo "model";
// Cada "view" exibe os dados de uma determinada maneira;
// 1- ==== a primeira "view" é uma "tree":
QTreeView *tree = new QTreeView(splitter);
tree->setModel(model);
// habilita classificação na tree:
tree->setSortingEnabled(true);
// classifica
tree->sortByColumn(0);
// expande toda a árvore:
tree->expandAll();
// força largura de todas as colunas
// para exibição completa do texto dos seus itens
for (col = 0; col < totCols; ++col)
tree->resizeColumnToContents(col);
// configura o header para permitir mudança na ordem de classificacão:
QHeaderView * hdrTree = tree->header();
hdrTree->setClickable (true);
hdrTree->setSortIndicator(0,Qt::AscendingOrder);
hdrTree->setSortIndicatorShown(true);
hdrTree->setMovable(true); // permite mover colunas do header
// 2- ==== a segunda "view" é uma "table"
QTableView *table = new QTableView(splitter);
table->setModel(model);
table->setAlternatingRowColors(true);
// habilita classificação na table:
table->setSortingEnabled(true);
// classifica
table->sortByColumn(0);
// configura o header para permitir mudança na ordem de classificacão:
QHeaderView * hdrTable = table->horizontalHeader();
hdrTable->setClickable (true);
hdrTable->setSortIndicator(0,Qt::AscendingOrder);
hdrTable->setSortIndicatorShown(true);
hdrTable->setMovable(true); // permite mover colunas do header
// 3- ==== a terceira view é uma "list":
QListView *list = new QListView(splitter);
list->setModel(model);
// 4- ==== a quarta "view" é uma "comboBox"
QComboBox *combo = new QComboBox;
combo->setModel(model);
// configura a "splitter" definindo a largura de cada "view"
int width = 800;
QList< int > cols;
cols << int(width* 0.45) << int(width*0.45) << int(width*0.1);
splitter->setSizes(cols);
// layout para agrupar a "combo" e a "splitter":
QGridLayout * glayMain = new QGridLayout;
main_wg->setLayout( glayMain);
glayMain->addWidget( combo, 0, 1); // linha 0, coluna 0;
glayMain->setRowMinimumHeight(1, glayMain->verticalSpacing() * 4); // linha 1: linha de separação
glayMain->addWidget( splitter, 2, 0, 1, 3 ); // linha 2, coluna 0, rowSpan 1, colSpan 3
main_wg->setWindowTitle("06_standard - 4 'views' usando o mesmo 'model' (StandardModel) - recursivo");
main_wg->resize(800,500);
//.........这里部分代码省略.........
示例9: QDialog
DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent)
: QDialog(parent), predefinedTokens(_predefinedTokens)
{
nameLabel = new QLabel(tr("&Name:"));
nameEdit = new QLineEdit(tr("Token"));
nameEdit->selectAll();
nameLabel->setBuddy(nameEdit);
colorLabel = new QLabel(tr("C&olor:"));
colorEdit = new QComboBox;
colorEdit->addItem(tr("white"), "w");
colorEdit->addItem(tr("blue"), "u");
colorEdit->addItem(tr("black"), "b");
colorEdit->addItem(tr("red"), "r");
colorEdit->addItem(tr("green"), "g");
colorEdit->addItem(tr("multicolor"), "m");
colorEdit->addItem(tr("colorless"), QString());
colorLabel->setBuddy(colorEdit);
ptLabel = new QLabel(tr("&P/T:"));
ptEdit = new QLineEdit;
ptLabel->setBuddy(ptEdit);
annotationLabel = new QLabel(tr("&Annotation:"));
annotationEdit = new QLineEdit;
annotationLabel->setBuddy(annotationEdit);
destroyCheckBox = new QCheckBox(tr("&Destroy token when it leaves the table"));
destroyCheckBox->setChecked(true);
QGridLayout *grid = new QGridLayout;
grid->addWidget(nameLabel, 0, 0);
grid->addWidget(nameEdit, 0, 1);
grid->addWidget(colorLabel, 1, 0);
grid->addWidget(colorEdit, 1, 1);
grid->addWidget(ptLabel, 2, 0);
grid->addWidget(ptEdit, 2, 1);
grid->addWidget(annotationLabel, 3, 0);
grid->addWidget(annotationEdit, 3, 1);
grid->addWidget(destroyCheckBox, 4, 0, 1, 2);
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
tokenDataGroupBox->setLayout(grid);
cardDatabaseModel = new CardDatabaseModel(db, this);
cardDatabaseDisplayModel = new CardDatabaseDisplayModel(this);
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
chooseTokenFromAllRadioButton = new QRadioButton(tr("Show &all tokens"));
connect(chooseTokenFromAllRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromAll(bool)));
chooseTokenFromDeckRadioButton = new QRadioButton(tr("Show tokens from this &deck"));
connect(chooseTokenFromDeckRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromDeck(bool)));
QTreeView *chooseTokenView = new QTreeView;
chooseTokenView->setModel(cardDatabaseDisplayModel);
chooseTokenView->setUniformRowHeights(true);
chooseTokenView->setRootIsDecorated(false);
chooseTokenView->setAlternatingRowColors(true);
chooseTokenView->setSortingEnabled(true);
chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
chooseTokenView->resizeColumnToContents(0);
chooseTokenView->header()->setStretchLastSection(false);
chooseTokenView->header()->hideSection(1);
chooseTokenView->header()->hideSection(2);
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
if (predefinedTokens.isEmpty())
chooseTokenFromAllRadioButton->setChecked(true);
else {
chooseTokenFromDeckRadioButton->setChecked(true);
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
}
QVBoxLayout *tokenChooseLayout = new QVBoxLayout;
tokenChooseLayout->addWidget(chooseTokenFromAllRadioButton);
tokenChooseLayout->addWidget(chooseTokenFromDeckRadioButton);
tokenChooseLayout->addWidget(chooseTokenView);
QGroupBox *tokenChooseGroupBox = new QGroupBox(tr("Choose token from list"));
tokenChooseGroupBox->setLayout(tokenChooseLayout);
QVBoxLayout *leftVBox = new QVBoxLayout;
leftVBox->addWidget(tokenDataGroupBox);
leftVBox->addStretch();
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addLayout(leftVBox);
hbox->addWidget(tokenChooseGroupBox);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(hbox);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
//.........这里部分代码省略.........