<div dir="ltr"><div>Thanks again, Maurizio, good stuff!<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 20, 2021 at 2:34 AM Maurizio Berti <<a href="mailto:maurizio.berti@gmail.com">maurizio.berti@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><br><div>As far as I know, it's not clearly specified anywhere (there's a generic description here: <a href="https://doc.qt.io/qt-5/model-view-programming.html#mime-data" target="_blank">https://doc.qt.io/qt-5/model-view-programming.html#mime-data</a> ), but you can find it in the sources of QAbstractItemModel:mimeData, which creates a QDataStream with data encoded using :itemData() in the form:</div><div><br></div><div>stream << row << column << itemData(index)</div><div><br></div><div>(note that the above syntax is also available on PyQt, while unfortunately it's not possible with the opposite >> assignment, due to Python dynamic typing)</div></div></div></div></div></div></div></blockquote><div><br></div><div>I see. I've seen a suggestion on SO that I thought was interesting. Instead of learning how to decode this format, one can write</div><div>
<pre class="gmail-lang-cpp gmail-s-code-block gmail-hljs"><code> model = <span class="gmail-hljs-built_in">QStandardItemModel</span>()
model.<span class="gmail-hljs-built_in">dropMimeData</span>(event.<span class="gmail-hljs-built_in">mimeData</span>(), Qt.CopyAction, <span class="gmail-hljs-number">0</span>,<span class="gmail-hljs-number">0</span>, <span class="gmail-hljs-built_in">QModelIndex</span>())</code></pre>
</div><div>and then simply read the items from this model. Not that useful now that you told me the format, anyway...</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>Going a bit beyond this particular example, what happens if the method mimeData has a list with multiple types? Method mimeData is supposed to return a single QMimeData, so there will be a single encoding of the data, and if so, for which of the multiple mime types?</div></div></div></blockquote><div><br></div><div>In theory, you should always ensure that the format is application/x-qabstractitemmodeldatalist before going on with this implementation; according to your needs, you could always implement your own alternatives for other types of mime data.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>Also, in case of multiple supported mime types, how can dropMimeData know the format in which 'data' is encoded? It does not seem QMimeData provides a method indicating its format.<br></div></div></div></blockquote><div><br></div><div>By default there is only one supported mime type (x-qabstractitemmodeldatalist) for models, but QMimeData can theoretically support any serializable content set using setData(), and you can add that support by implementing mimeData() (just override it, call the base implementation and then add more data formats): for instance, QStandardItemModel also creates application/x-qstandarditemmodeldatalist (which it uses for itself when dropping).</div></div></div></div></div></div></div></blockquote><div><br></div><div>You seem to be talking about the possibility of *changing* the chosen format to a different one but still supporting a single format, but I am talking about mimeTypes() returning a list with *more* than one type, making the model have to support multiple formats at the same time. It's not clear to me how to do that in mimeData(), dropMimeData() and QMimeData. <br></div><div><br></div><div>In that scenario, it sounds like mimeData() would have to produce MIME data in multiple formats, and dropMimeData would have to support data in multiple formats. For one thing, it's not clear how to check the format of a QMimeData object. For another, it isn't clear how mimeData() can return a single QMimeData while supporting multiple formats.</div><div><br></div>Thanks,</div><div class="gmail_quote"><br></div><div class="gmail_quote">Rodrigo<br></div></div>