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


C++ QTreeView::indexAt方法代码示例

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


在下文中一共展示了QTreeView::indexAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: showSongsContextMenu

void MainWindow::showSongsContextMenu(QPoint point)
{
    QTreeView *songs = (QTreeView*)ui->tvSongs;
    if(songs->indexAt(point).isValid()) {
        QList<QAction *> actions;

        QAction *action = new QAction(songs);
        action->setText(tr("Play"));
        connect(action, SIGNAL(triggered()), this, SLOT(playAudio()));
        actions.append(action);

        action = new QAction(songs);
        action->setText(tr("Delete"));
        connect(action, SIGNAL(triggered()), this, SLOT(deleteAudio()));
        actions.append(action);

        action = new QAction(songs);
        action->setSeparator(true);
        actions.append(action);

        QList<Playlist> pls = dp->getPlaylists();
        int n = pls.count();
        QSignalMapper* signalMapper = new QSignalMapper (this);
        for( int i=0; i<n; i++ )
        {
            action = new QAction(songs);
            action->setText("Add to " + pls[i].title);
            connect(action, SIGNAL(triggered()), signalMapper, SLOT(map()));
            signalMapper->setMapping (action, pls[i].id) ;
            actions.append(action);
        }
        connect (signalMapper, SIGNAL(mapped(int)), this, SLOT(addAudioToPlaylist(int)));
        QMenu::exec(actions, songs->mapToGlobal(point));
    }
开发者ID:victorkifer,项目名称:VKAudioPlayer,代码行数:34,代码来源:mainwindow.cpp

示例2: showPlaylistsContextMenu

void MainWindow::showPlaylistsContextMenu(QPoint point)
{
    QTreeView *playlists = (QTreeView*)ui->tvPlaylists;
    if(playlists->indexAt(point).isValid()) {
        QStandardItemModel *model = (QStandardItemModel*)playlists->model();
        QStandardItem *item = model->itemFromIndex(playlists->indexAt(point));
        int data = item->data(DATA_KEY_PLAYLIST).toInt();
        QList<QAction *> actions;
        QAction *action;

        switch(data) {
            case DATA_SEARCH:
                break;
            case DATA_EMPTY:
                action = new QAction(playlists);
                action->setText(tr("Add"));
                connect(action, SIGNAL(triggered()), this, SLOT(addPlaylist()));
                actions.append(action);
                break;
            case DATA_HISTORY:
                break;
            default:
                action = new QAction(playlists);
                action->setText(tr("Delete"));
                connect(action, SIGNAL(triggered()), this, SLOT(deletePlaylist()));
                actions.append(action);
                break;
        }
        if(actions.count() > 0)
        {
            point.setX(point.x()-10);
            point.setY(point.y()+30);
            QMenu::exec(actions, playlists->mapToGlobal(point));
        }
    }
}
开发者ID:victorkifer,项目名称:VKAudioPlayer,代码行数:36,代码来源:mainwindow.cpp


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