Re: QSignalMapper, QMenu and custom context menu
Thanks to this thread, I discovered QSignalMapper, and found this nice example in Qt's doc:
Code:
{
for (int i = 0; i < texts.size(); ++i) {
connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(button, texts[i]);
gridLayout->addWidget(button, i / 3, i % 3);
}
connect(signalMapper,
SIGNAL(mapped
(QString)),
setLayout(gridLayout);
}
My question is: can I use the above approach with custom context menus, thus?
Code:
class MyCustomMenu
: QMenu { /* do as above except map (QAction*, actionText) through signalMapper */
};
Would this work? If not this, what do most people do when you have a long list (say, more than 5-8) of context menu actions?
Thanks for your insightful comments.
Added after 1 40 minutes:
As it happens, my Google search before my posting was not useful. It's funny how juxtaposing a few words in Google search fetches a different set of hits ... this link clearly illustrates what I want to do, that too with the function pointer idiom, which is better, except if you have overloading. Even with overloading it is not at all bad.
Still I would like the opinion of Qt experts on the choice of idioms. Thanks.
Re: QSignalMapper, QMenu and custom context menu
Quote:
Originally Posted by
NameRakes
Would this work? If not this, what do most people do when you have a long list (say, more than 5-8) of context menu actions?
Yes, basically the same code, just using the action's "triggered()" signal instead of a button's "clicked()" signal.
Cheers,
_