Note that there are some explanatory texts on larger screens.

plurals
  1. POQt: adapting signals / binding arguments to slots?
    primarykey
    data
    text
    <p>Is there any way to bind arguments to slots ala <a href="http://www.boost.org/doc/libs/1_38_0/libs/bind/bind.html" rel="nofollow noreferrer" title="boost::bind">boost::bind</a>?</p> <p>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:</p> <pre><code>void MyWindow::contextMenuEvent (QContextMenuEvent* event) { m_column = view-&gt;columnAt (event-&gt;x()); QMenu menu; menu.addAction (tr ("Hide Column"), this, SLOT (hideColumn ())); // .. run the menu, etc } </code></pre> <p>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 <code>hideColumn</code> slot:</p> <pre><code>void MyWindow::hideColumn () { view-&gt;setColumnHidden (m_column, true); } </code></pre> <p>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:</p> <pre><code>menu.addAction (tr ("Hide Column"), boost::bind (&amp;MyWindow::hideColumn, this, event-&gt;columnAt (event-&gt;x())); </code></pre> <p>Or even better yet adapting the <a href="http://doc.trolltech.com/4.3/qaction.html#triggered" rel="nofollow noreferrer">QAction::triggered</a> signal and attaching it to the <a href="http://doc.trolltech.com/4.3/qtreeview.html#hideColumn" rel="nofollow noreferrer">QTreeView::hideColumn</a> slot, which takes the column index as an argument:</p> <pre><code>menu.addAction (tr ("Hide Column"), boost::bind (&amp;QTreeView::hideColumn, view, event-&gt;columnAt (event-&gt;x()))); </code></pre> <p>Is any of this do-able?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload