当前位置: 首页>>代码示例>>C++>>正文


C++ QStandardItemModel::horizontalHeaderItem方法代码示例

本文整理汇总了C++中QStandardItemModel::horizontalHeaderItem方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItemModel::horizontalHeaderItem方法的具体用法?C++ QStandardItemModel::horizontalHeaderItem怎么用?C++ QStandardItemModel::horizontalHeaderItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QStandardItemModel的用法示例。


在下文中一共展示了QStandardItemModel::horizontalHeaderItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:Ejik,项目名称:bpp2,代码行数:59,代码来源:importer.cpp

示例2: loadPlaylists

void MainWindow::loadPlaylists()
{
    QTreeView *playlists = (QTreeView*)ui->tvPlaylists;

    QStandardItemModel *model = new QStandardItemModel(3,1);
    QStandardItem *item = new QStandardItem(QString(tr("Search")));
    item->setData(DATA_SEARCH, DATA_KEY_PLAYLIST);
    item->setEditable(false);
    model->setItem(0, 0, item);
    item = new QStandardItem(QString(tr("History")));
    item->setData(DATA_HISTORY, DATA_KEY_PLAYLIST);
    item->setEditable(false);
    model->setItem(1, 0, item);
    item = new QStandardItem(QString(tr("Playlists")));
    item->setData(DATA_EMPTY, DATA_KEY_PLAYLIST);
    item->setEditable(false);
    QList<Playlist> pls = dp->getPlaylists();
    int n = pls.count();
    for( int i=0; i<n; i++ )
    {
      QStandardItem *child = new QStandardItem(pls[i].title);
      child->setData(pls[i].id, DATA_KEY_PLAYLIST);
      child->setEditable(false);
      item->appendRow(child);
    }
    model->setItem(2, 0, item);
    model->setHorizontalHeaderItem( 0, new QStandardItem(tr("Library")));
    model->horizontalHeaderItem(0)->setEditable(false);
    model->horizontalHeaderItem(0)->setEnabled(false);

    playlists->setModel(model);
    playlists->setContextMenuPolicy(Qt::CustomContextMenu);

    QModelIndexList indexes = model->match(model->index(2,0), Qt::DisplayRole, "*", -1, Qt::MatchWildcard|Qt::MatchRecursive);
    playlists->expand(indexes[0]);

    connect(playlists->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(loadPlaylist()));
}
开发者ID:victorkifer,项目名称:VKAudioPlayer,代码行数:38,代码来源:mainwindow.cpp


注:本文中的QStandardItemModel::horizontalHeaderItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。