I am working on a uni project, and our goal is to create a program that scans all img / video / movie files in a selected directory, saves them in a database and then organizes them in an organized manner (using QTreeWidgetItem). The program allows you to do some things, such as reading files, opening them, etc. Now the problem is that I would like to right-click one of the files and open a menu with many options, such as Open Directory, delete the file ...
I just donβt know how to make this right-click menu, I am new to QT, I tried to do this:
connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(openMenu(QTreeWidgetItem *, int)));
I tried reinstalling the itemClicked method but can't find how to find out if he right-clicked correctly and I think that maybe I'm wrong.
I was inspired by this:
connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(opennMusic(QTreeWidgetItem *, int)));
which launches the music file with a double click.
If you need more pieces of code, just let me know :).
Edit after the last andy comment to display the new code:
void AffichageMusique::lireMusique(QTreeWidgetItem *item, int column)
{
if(item->text(6)!=NULL)
{
Phonon::MediaSource source(item->text(6));
mediaObject->setCurrentSource(source);
mediaObject->play();
}
}
void AffichageMusique::vueArtiste()
{
layout->removeWidget(treeWidget);
treeWidget = new QTreeWidget();
QAction* pOpenDir = new QAction(tr("Play music"),treeWidget );
treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
treeWidget->addAction(pOpenDir);
.......
}
void AffichageMusique::pOpenDir()
{
QTreeWidget * treeWidget = new QTreeWidget();
QTreeWidgetItem * QTreeWidgetI= treeWidget->currentItem();
lireMusique(QTreeWidgetI, 6);
}
Even if I delete QTreeWidget * treeWidget = new QTreeWidget (); line it wont work, I see the menu when I right-click, but when I press PLAY, nothing happens.