Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QStandardItem custom drag MIME



  • I'm desperately trying to figure out how I can set custom data MIME type and data on a QStandardItem. I would have expected that QStandardItem provides something similar to QStandardItem::setMimeData() which would allow to set the mime data (and type) for each individual item. However, that doesn't appear to be the case.

    What is the expected way of achieving this? I usually write my own models inheriting from QAbstractItemModel but the code I'm working on at the moment uses QStandardItemModel. Do I have to subclass it and re-implement QStandardItemModel::mimeData() ?


  • Lifetime Qt Champion

    Hi,

    AFAIR, yes that's the way to do it.



  • Got it working that way (no surprise there).

    However, I'd like to understand why QStandardItem does not offer a setMimeData() function. Looking at the existing design of QStandardItemModel and QStandardItem it seems feasible to implement this. Is this simply not implemented because nobody ever did it or is there a technical reason for this?


  • Lifetime Qt Champion

    @Joel-Bodenmann said in QStandardItem custom drag MIME:

    However, I'd like to understand why QStandardItem does not offer a setMimeData() function.

    Because noone wants to create a mime data just on suspicion for every item.


Log in to reply