Hello friends,
I have create an actions like this
myAction
= new QAction(QIcon(":/IMAGES/error.png"),tr
("&TestAction"),
this);
connect(myAction,
SIGNAL(triggered
()),
this,
SLOT(openFileInTable
( const QModelIndex & )));
myAction = new QAction(QIcon(":/IMAGES/error.png"),tr("&TestAction"), this);
connect(myAction, SIGNAL(triggered()), this, SLOT(openFileInTable( const QModelIndex & )));
To copy to clipboard, switch view to plain text mode
Before creating my action I make this:
trackFolder->setContextMenuPolicy(Qt::CustomContextMenu);
connect(trackFolder,
SIGNAL(customContextMenuRequested
(const QPoint &)),
this,
SLOT(showContextMenu
(const QPoint &)));
trackFolder->setContextMenuPolicy(Qt::CustomContextMenu);
connect(trackFolder, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showContextMenu(const QPoint &)));
To copy to clipboard, switch view to plain text mode
My contextmenu function is(trackfolder is a Qtreeview) :
void Window
::showContextMenu(const QPoint &position
) {
QList<QAction *> actions;
if (trackFolder->indexAt(position).isValid()) {
actions.append(myAction);
}
if (actions.count() > 0)
QMenu::exec(actions, trackFolder
->mapToGlobal
(position
));
}
void Window::showContextMenu(const QPoint &position)
{
QList<QAction *> actions;
if (trackFolder->indexAt(position).isValid()) {
actions.append(myAction);
}
if (actions.count() > 0)
QMenu::exec(actions, trackFolder->mapToGlobal(position));
}
To copy to clipboard, switch view to plain text mode
So when I rightclick an item it shows me correctly the item, but the given function does not enter. But when I replace
....SLOT(openFileInTable( const QModelIndex & )));
To copy to clipboard, switch view to plain text mode
with the normal quit function like this
....SLOT(quit()));
....SLOT(quit()));
To copy to clipboard, switch view to plain text mode
the Application quits normally.
What do I wrong. My Slot in the contextmenu that must be run is declared like this:
void openFileInTable(const QModelIndex & index);
To copy to clipboard, switch view to plain text mode
How can I run my slot in the contextmenu???
Bookmarks