<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Best Practice For Sharing Selection Model And Proxy Models With Multiple Views]]></title><description><![CDATA[<p dir="auto">I may be so off on this one.</p>
<p dir="auto">Say ViewA has ProxyModelA and selection model "SelectModelA".<br />
ViewB would like share SelectModelA with viewA.<br />
However ViewB uses a different model, say ProxyModelB.<br />
Both ProxyModelA and ProxyModelB sit on top (say directly for the time being) of the real deal - call it "ModelRoot".</p>
<p dir="auto">When it comes to selection, viewB will receive model indexes from "ProxyModelA".  viewB doesn't understand "ProxyModelA".  So it has to either convert it or a conversion has to take place between.</p>
<p dir="auto">Case 1 might look like the following since the model ptr is part of the modelindex (if this utterly horrible, say so!)</p>
<p dir="auto">@<br />
...<br />
connect(standard_qtreeview_selection_model,SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),<br />
my_graphics_scene,SLOT(slot_model_select(QModelIndex,QModelIndex)));<br />
...</p>
<p dir="auto">void MyGraphicsScene::slot_model_select(const QModelIndex&amp; idx_in,<br />
const QModelIndex&amp; prev_idx_in)<br />
{<br />
QModelIndex idx = idx_in;<br />
QModelIndex prev_idx = prev_idx_in;</p>
<pre><code>const QAbstractProxyModel* pmodel = dynamic_cast&lt;const QAbstractProxyModel*&gt;
                                    (idx.model());
if ( pmodel ) {
    idx = pmodel-&gt;mapToSource(idx_in);
    prev_idx = pmodel-&gt;mapToSource(prev_idx_in);
}
</code></pre>
<p dir="auto">@</p>
<p dir="auto">Another example, in the case of a Delegate that launches an editor which is a qtableview, the delegate may create a little proxy model based on the current model which could be a proxy itself... and well it's complicated to explain the interaction with the selection model... ughh</p>
<p dir="auto">The thing is, I can do this, I just feel off... and hoping there was some advice.</p>
]]></description><link>https://forum.qt.io/topic/6139/best-practice-for-sharing-selection-model-and-proxy-models-with-multiple-views</link><generator>RSS for Node</generator><lastBuildDate>Thu, 11 Jun 2026 09:32:15 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/6139.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 May 2011 19:56:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Best Practice For Sharing Selection Model And Proxy Models With Multiple Views on Thu, 26 May 2011 14:54:49 GMT]]></title><description><![CDATA[<p dir="auto">Heh, nice analogy. In my experience model/view selection handling can be a huge sword with a morning star at the butt end if you're not careful. I do like the framework though.</p>
<p dir="auto">Edit: removed the link to <a href="http://en.wikipedia.org/wiki/Morning_star_(weapon)" target="_blank" rel="noopener noreferrer nofollow ugc">http://en.wikipedia.org/wiki/Morning_star_(weapon)</a> because I couldn't hide it neatly.</p>
]]></description><link>https://forum.qt.io/post/89713</link><guid isPermaLink="true">https://forum.qt.io/post/89713</guid><dc:creator><![CDATA[Franzk]]></dc:creator><pubDate>Thu, 26 May 2011 14:54:49 GMT</pubDate></item><item><title><![CDATA[Reply to Best Practice For Sharing Selection Model And Proxy Models With Multiple Views on Thu, 26 May 2011 14:50:15 GMT]]></title><description><![CDATA[<p dir="auto">Franzk, thanks.  This sort of programming, using a framework, is new to me.  I've always done lower level stuff.  I feel like I'm wielding a huge sword.  It's most likely that I will cut off my own foot here and there.  I appreciate the guidance and tips.</p>
]]></description><link>https://forum.qt.io/post/89711</link><guid isPermaLink="true">https://forum.qt.io/post/89711</guid><dc:creator><![CDATA[texas]]></dc:creator><pubDate>Thu, 26 May 2011 14:50:15 GMT</pubDate></item><item><title><![CDATA[Reply to Best Practice For Sharing Selection Model And Proxy Models With Multiple Views on Thu, 26 May 2011 14:31:56 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="texas" date="1306418753"]Franzk, I think in this case, so far, the proxy modelling is worth the extra trouble because it is making it so I don't have to fiddle with the views.  In theory, I am not using <em>different</em> models, I am using two lenses (proxies) on the <em>same</em> model.[/quote]I fully understand what you want to achieve, since I tried to achieve the same. That doesn't change the fact that you may have to make some behavioral decisions that can compromise the predictability of your project. I hope you can make it work though.</p>
]]></description><link>https://forum.qt.io/post/89704</link><guid isPermaLink="true">https://forum.qt.io/post/89704</guid><dc:creator><![CDATA[Franzk]]></dc:creator><pubDate>Thu, 26 May 2011 14:31:56 GMT</pubDate></item><item><title><![CDATA[Reply to Best Practice For Sharing Selection Model And Proxy Models With Multiple Views on Thu, 26 May 2011 14:15:16 GMT]]></title><description><![CDATA[<p dir="auto">Andre, thanks for the links.  Yes... perfect.  I actually thought yesterday, "What I probably need is something outside to encapsulate hopping up and down a proxy chain..."  Even if the code won't work for me, at least I'm know I'm not doing something crazy.</p>
]]></description><link>https://forum.qt.io/post/89703</link><guid isPermaLink="true">https://forum.qt.io/post/89703</guid><dc:creator><![CDATA[texas]]></dc:creator><pubDate>Thu, 26 May 2011 14:15:16 GMT</pubDate></item><item><title><![CDATA[Reply to Best Practice For Sharing Selection Model And Proxy Models With Multiple Views on Thu, 26 May 2011 14:05:53 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for both responses.</p>
<p dir="auto">Franzk, I think in this case, so far, the proxy modelling is worth the extra trouble because it is making it so I don't have to fiddle with the views.  In theory, I am not using <em>different</em> models, I am using two lenses (proxies) on the <em>same</em> model.</p>
<p dir="auto">Andre, thanks.  I am looking forward to reading the blog and checking out the code.</p>
]]></description><link>https://forum.qt.io/post/89700</link><guid isPermaLink="true">https://forum.qt.io/post/89700</guid><dc:creator><![CDATA[texas]]></dc:creator><pubDate>Thu, 26 May 2011 14:05:53 GMT</pubDate></item><item><title><![CDATA[Reply to Best Practice For Sharing Selection Model And Proxy Models With Multiple Views on Thu, 26 May 2011 07:34:09 GMT]]></title><description><![CDATA[<p dir="auto">Selections and proxy models are indeed a pain to deal with. Luckely, you don't have to reinvent the wheel completely. Steveire has "blogged":<a href="http://steveire.wordpress.com/2010/04/20/sharing-a-qitemselection-between-views-through-proxy-models/" target="_blank" rel="noopener noreferrer nofollow ugc">http://steveire.wordpress.com/2010/04/20/sharing-a-qitemselection-between-views-through-proxy-models/</a> about this issue a couple of times, and has contributed "some code":<a href="http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKLinkItemSelectionModel.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKLinkItemSelectionModel.html</a> to KDE that you could lift and use.</p>
]]></description><link>https://forum.qt.io/post/89634</link><guid isPermaLink="true">https://forum.qt.io/post/89634</guid><dc:creator><![CDATA[andre]]></dc:creator><pubDate>Thu, 26 May 2011 07:34:09 GMT</pubDate></item><item><title><![CDATA[Reply to Best Practice For Sharing Selection Model And Proxy Models With Multiple Views on Wed, 25 May 2011 20:54:39 GMT]]></title><description><![CDATA[<p dir="auto">Hm. I think I tried to achieve the same you are doing here. It is hard to do and requires a lot of data management. I came to the following conclusion after achieving it: it's useless. Really. Semantically it doesn't make any sense to have two views with different models and then try to combine some selection out of it. One view may see data that the other doesn't and boom, there goes the predictability of your UI. Think hard if you really need this functionality.</p>
]]></description><link>https://forum.qt.io/post/89590</link><guid isPermaLink="true">https://forum.qt.io/post/89590</guid><dc:creator><![CDATA[Franzk]]></dc:creator><pubDate>Wed, 25 May 2011 20:54:39 GMT</pubDate></item></channel></rss>