本文整理汇总了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));
}
示例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));
}
}
}