[Qt-interest] Help on QAction
phil prentice
philp.cheer at talktalk.net
Tue Mar 10 17:26:14 CET 2009
Hi all
I need to create a variable length context menu. I have used code like this
to do it:-
for(int i = 0; i < count; i++)
{
action = instrumentMenu.addAction(array[i]);
/* connect(action, SIGNAL(triggered()), this, SLOT(instMenu())); */
}
CurInstLabel->setContextMenuPolicy(Qt::CustomContextMenu);
connect(CurInstLabel, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showInstContextMenu(const QPoint &)));
My showInstContextMenu() slot looks like this.
void QTdcwb::showInstContextMenu(const QPoint &)
{
QAction *retAction= instrumentMenu.exec(QCursor::pos());
}
I know which menu option has been selected by the retAction pointer returned
from the exec. Each menu choice has some other data associated with that
choice. I could use retAction to identify which item was selected and then
access the appropriate data. Is there a better way? I cant use the
triggered signal because it wont tell me which menu item was selected
(without setting a slot up per action).
I just need a means of accessing the data associated with a menu choice
(action), without having to do a search through the action list.
Thanks
Phil
More information about the Qt-interest-old
mailing list