Is there any way to bind arguments to slots ala boost::bind?
Here's a for-instance. I have a window with a tree view, and I want to allow the user to hide a column from a context menu. I end up doing something like:
void MyWindow::contextMenuEvent (QContextMenuEvent* event) {
m_column = view->columnAt (event->x());
QMenu menu;
menu.addAction (tr ("Hide Column"), this, SLOT (hideColumn ()));
// .. run the menu, etc
}
I need to capture the index of the column over which the context menu was activated and store it in a member variable that is used by my window's hideColumn
slot:
void MyWindow::hideColumn () {
view->setColumnHidden (m_column, true);
}
What I'd really like is to be able to bind the column number to my slot when I create the menu so I don't need this member variable. Basically the Qt equivalent of:
menu.addAction (tr ("Hide Column"),
boost::bind (&MyWindow::hideColumn, this,
event->columnAt (event->x()));
Or even better yet adapting the QAction::triggered signal and attaching it to the QTreeView::hideColumn slot, which takes the column index as an argument:
menu.addAction (tr ("Hide Column"),
boost::bind (&QTreeView::hideColumn, view,
event->columnAt (event->x())));
Is any of this do-able?