Hello!
I am working on a uni project and our goal is to make a program that scans all img/video/movie files on a selected directory, stores them in a database and then shozs them in an organised way (using QTreeWidgetItem). Program allows you to do some stuff like read the files, open them and so on. Now, the problem is that I would like to Right click one of the files and pop up a Menu with many options like Open Directory, delete file...
I just don' know how to make that right click menu, I'm kinda new to QT, I tried making this:
connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(openMenu(QTreeWidgetItem *, int)));
I tried redifining the itemClicked method but can't seem to find how to know if it's a right click and i think I might be trying it the wrong way.
I inspired from this:
connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(opennMusic(QTreeWidgetItem *, int)));
which executes a music file on double click.
If you need more code parts just let me know :).
Thank you!!
Edit after andy's last comment to show new code:
include "affichagemusique.h"
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);
.......
}
// later on on the code
void AffichageMusique::pOpenDir()
{
QTreeWidget * treeWidget = new QTreeWidget();
QTreeWidgetItem * QTreeWidgetI= treeWidget->currentItem();
lireMusique(QTreeWidgetI, 6);
}
Even if I remove the QTreeWidget * treeWidget = new QTreeWidget(); line it wont work, I see the menu when i right click but when I click PLay, nothing happens.
Thanks for your help!