本文整理汇总了C++中QStandardItemModel::columnCount方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItemModel::columnCount方法的具体用法?C++ QStandardItemModel::columnCount怎么用?C++ QStandardItemModel::columnCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItemModel
的用法示例。
在下文中一共展示了QStandardItemModel::columnCount方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ImportData
QStandardItemModel* Importer::ImportData()
{
QString current_path = QDir::currentPath() + "//" + datafilename();
QFile file(QDir::toNativeSeparators(current_path));
if(!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, tr("Ошибка"), file.errorString());
qDebug() << "Error in open file: " + file.errorString();
}
QTextStream in(&file);
in.setCodec(QTextCodec::codecForName("IBM 866"));
QString line = in.readLine();
QStringList fields = line.split(separator());
QStandardItemModel *model = new QStandardItemModel(0, fields.count()+1);
model->setHorizontalHeaderLabels(fields);
// Заменяем заголовки столбцов
for (int i = 0; i < model->columnCount() - 1; i++)
{
QStandardItem *item = model->horizontalHeaderItem(i);
QString item_text = item->text();
if (item_text.compare(tr("ФИОТБН")) == 0) {
item->setText(tr("Отправитель"));
} else if (item_text.compare(tr("Кому")) == 0) {
item->setText(tr("Получатель"));
}
}
int last_col_idx = model->columnCount() - 1;
model->setHorizontalHeaderItem(last_col_idx, new QStandardItem(tr("Состояние")));
model->horizontalHeaderItem(last_col_idx)->setText(tr("Состояние"));
// model->setHorizontalHeaderItem(0, new QStandardItem(tr("ТБН")));
// model->setHorizontalHeaderItem(1, new QStandardItem(tr("Отправитель")));
// model->setHorizontalHeaderItem(4, new QStandardItem(tr("Получатель")));
// model->setHorizontalHeaderItem(12, new QStandardItem(tr("Состояние")));
while(!in.atEnd())
{
QString line = in.readLine();
QStringList fields = line.split(separator());
QStringListIterator it(fields);
QList<QStandardItem *> data;
while (it.hasNext())
{
data << new QStandardItem(it.next());
}
model->appendRow(data);
}
file.close();
return model;
}
示例2: loadScore
void MainWindow::loadScore()
{
//QMessageBox::information(0, "wer", "wer");
ui->tableView->reset();
QStandardItemModel *model = new QStandardItemModel();
QList< QList<QStandardItem *> > list = user->scoreDetail();
for (int i = 0; i < list.count(); i++)
{
model->insertRow(i, list.at(i));
qDebug() << list.at(i).at(1)->text();
}
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Course Name"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Middleterm Score"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Final Score"));
for (int i = 0; i < model->rowCount(); i++)
for (int j = 0; j < model->columnCount(); j++)
model->item(i,j)->setEditable(false);
ui->tableView->setModel(model);
ui->tableView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
ui->tableView->resizeColumnToContents(1);
ui->tableView->resizeColumnToContents(2);
// ui->tableView->setColumnWidth(2, 100);
// ui->tableView->setColumnWidth(3, 100);
ui->tableView->verticalHeader()->hide();
ui->tableView->setSelectionMode(QAbstractItemView::NoSelection);
}
示例3: openDatas
void MainWindow::openDatas(QString filename)
{
QStandardItemModel *model = new QStandardItemModel;
QFile fichier(filename);
QDomDocument *doc = new QDomDocument("docXml");
QDomElement elem;
QList<int> *currentChild = new QList<int>();
QList<int> *nodesLength = new QList<int>();
int height = 0;
//open the selected file and get the xml document in doc
fichier.open(QIODevice::ReadWrite | QIODevice::Text);
doc->setContent(&fichier);
currentDocument = doc;
fichier.close();
//get the first element of the document
elem = doc->documentElement();
root = elem.tagName();
//get the height for the document and prepare the parameters to build the tree
heightXML(elem, &height);
for(int i = 0; i < height-1; i++)
{
currentChild->append(0);
nodesLength->append(0);
}
QStandardItem *item = new QStandardItem(elem.tagName());
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
//build the model and use it to be displayed using a QTreeView
buildTree(elem, model, item, nodesLength, 0, currentChild, -1);
//Modify the columns' headers
setColumnLabels(model);
this->model = model;
this->modelIsSet = true;
//set the to the tree
treeView->setModel(model);
treeView->expandAll();
for(int i = 0; i < model->columnCount(); i++)
{
treeView->resizeColumnToContents(i);
}
//Store the filename for the menu "Recent files"
setSettings(filename);
updateMenuRecentFiles();
QObject::connect(treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(showDetails(QModelIndex)));
}
示例4: populateTableView
void cHelpDlg::populateTableView(const QStringList &shortcuts, const QStringList &actions)
{
QStandardItemModel* model = new QStandardItemModel(shortcuts.size(), 2, this);
model->setHorizontalHeaderItem(0, new QStandardItem(""));
model->setHorizontalHeaderItem(1, new QStandardItem(tr("Action")));
_ui->tableView->setModel(model);
setStyleSheet("QTableView::item{padding: 2px;}");
for (int aK=0; aK< shortcuts.size(); ++aK)
{
QStandardItem *it0 = new QStandardItem(shortcuts[aK]);
QStandardItem *it1 = new QStandardItem(actions[aK]);
if (actions[aK].isEmpty())
{
QFont theFont = it0->font();
theFont.setBold(true);
it0->setFont(theFont);
}
it0->setFlags(it0->flags() & ~Qt::ItemIsEditable);
it1->setFlags(it1->flags() & ~Qt::ItemIsEditable);
model->setItem(aK, 0, it0);
model->setItem(aK, 1, it1);
}
_ui->tableView->horizontalHeader()->setStretchLastSection(true);
#if ELISE_QT_VERSION >=5
_ui->tableView->resizeColumnsToContents();
_ui->tableView->resizeRowsToContents();
#endif
int height = 0;
for(int row = 0; row < model->rowCount(); row++)
height += _ui->tableView->rowHeight(row);
#if ELISE_QT_VERSION >=5
int width = 0;
for(int column = 0; column < model->columnCount(); column++)
width += _ui->tableView->columnWidth(column);
_ui->tableView->resize(width, height);
#else
_ui->tableView->resize(400, height);
#endif
resize(_ui->tableView->width()+50,_ui->tableView->height() + _ui->okButton->height()+50);
}
示例5: itemChanged
void ModelsManager::itemChanged(QStandardItem* i)
{
QStandardItemModel* model = static_cast<QStandardItemModel*>(sender());
int row = i->row();
Register r;
r.name = model->item(row, 0)->text();
for (int i = 1; i < model->columnCount(); i++) {
r.value += model->item(row, i)->text() + ' ';
}
r.value = r.value.trimmed();
emit registerChanged(r);
}
示例6: clearDefaultRow
void Ui_pluginManagerWindow::clearDefaultRow(int defaultRow)
{
QStandardItemModel *model = (QStandardItemModel*)ui.pluginTableView->model();
QStandardItem *item = model->item(defaultRow, 0);
item->setData(false, PLUGIN_IS_DEFAULT);
for (int column = 0; column < model->columnCount(); column++)
{
QStandardItem *item = model->item(defaultRow, column);
QFont font = item->font();
font.setBold(false);
item->setFont(font);
}
}
示例7: initTestCase
void Ut_MListView::initTestCase()
{
static char *app_name[1] = { (char *) "./ut_mlistview" };
static int argc = 1;
app = new MApplication(argc, app_name);
MPannableViewport *viewport = new MPannableViewport();
viewport->resize(50, 100);
MList *controller = new MList(viewport);
m_subject = new MListView(controller);
MListModel *model = new MListModel();
model->setShowGroups(true);
QStandardItemModel *itemModel = new QStandardItemModel(4, 2);
for (int row = 0; row < itemModel->rowCount(); ++row) {
for (int column = 0; column < itemModel->columnCount(); ++column) {
QStandardItem *item = new QStandardItem(
QString("row %0, column %1").arg(row).arg(column));
itemModel->setItem(row, column, item);
}
}
QItemSelectionModel *selectionModel = new QItemSelectionModel(itemModel);
controller->setSelectionModel(selectionModel);
controller->setItemModel(itemModel);
model->setSelectionModel(selectionModel);
m_dummyWidget = new MDummyTestWidget();
connect(m_dummyWidget, SIGNAL(itemClickSignal()),
m_subject, SLOT(itemClick()));
model->setItemModel(itemModel);
m_subject->setModel(model);
m_subject->init();
}
示例8: loadElective
void MainWindow::loadElective()
{
//QMessageBox::information(0, "User", "Elective");
ui->tableView->reset();
QStandardItemModel *model = new QStandardItemModel();
//MyStandardItemModel *model = new MyStandardItemModel();
MyItemDelegate *delegate = new MyItemDelegate();
connect(model, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(saveElectiveChange(QStandardItem*)));
QList< QList<QStandardItem *> > list = user->electiveDetail();
for (int i = 0; i < list.count(); i++)
{
model->insertRow(i, list.at(i));
qDebug() << list.at(i).at(1)->text();
}
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Status"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Course ID"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Course Name"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Teacher ID"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Teacher Name"));
model->setHeaderData(5, Qt::Horizontal, QObject::tr("Course Addr."));
ui->tableView->setModel(model);
//ui->tableView->setItemDelegate(delegate);
for (int i = 0; i < model->columnCount(); i++)
ui->tableView->horizontalHeader()->setResizeMode(i, QHeaderView::Stretch);
//ui->tableView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
ui->tableView->resizeColumnToContents(1);
ui->tableView->resizeColumnToContents(2);
// ui->tableView->setColumnWidth(2, 100);
// ui->tableView->setColumnWidth(3, 100);
ui->tableView->verticalHeader()->hide();
ui->tableView->setSelectionMode(QAbstractItemView::NoSelection);
}
示例9: slotNewSelection
void ObservingList::slotNewSelection() {
bool found = false;
singleSelection = false;
noSelection = false;
showScope = false;
ui->ImagePreview->clearPreview();
ui->ImagePreview->setCursor( Qt::ArrowCursor );
QModelIndexList selectedItems;
QString newName;
SkyObject *o;
ui->SaveImage->setEnabled( false );
ui->DeleteImage->setEnabled( false );
QStandardItemModel *currentModel;
QList<SkyObject*> currList;
if ( sessionView ) {
selectedItems = m_SortModelSession->mapSelectionToSource( ui->SessionView->selectionModel()->selection() ).indexes();
currentModel = m_Session;
currList = sessionList();
} else {
selectedItems = m_SortModel->mapSelectionToSource( ui->TableView->selectionModel()->selection() ).indexes();
currentModel = m_Model;
currList = obsList();
}
if ( selectedItems.size() == currentModel->columnCount() ) {
newName = selectedItems[0].data().toString();
singleSelection = true;
//Find the selected object in the SessionList,
//then break the loop. Now SessionList.current()
//points to the new selected object (until now it was the previous object)
foreach ( o, currList ) {
if ( o->translatedName() == newName ) {
found = true;
break;
}
}
}