LordQt
16th February 2009, 14:40
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 & )));
Before creating my action I make this:
trackFolder->setContextMenuPolicy(Qt::CustomContextMenu);
connect(trackFolder, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showContextMenu(const QPoint &)));
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));
}
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 & )));
with the normal quit function like this
....SLOT(quit()));
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);
How can I run my slot in the contextmenu???
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 & )));
Before creating my action I make this:
trackFolder->setContextMenuPolicy(Qt::CustomContextMenu);
connect(trackFolder, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showContextMenu(const QPoint &)));
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));
}
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 & )));
with the normal quit function like this
....SLOT(quit()));
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);
How can I run my slot in the contextmenu???