[Solved] Drag item within QTableView



  • Hi Folks,

    I would like to implement a well usable drag functionality for rearranging item order within my QTableView. I'm using QStandardItemModel. I changed the following properties of the table in the UI designer of QtCreator:

    • dragEnabled -> true
    • dragDropOverwriteMode ->false
    • dragDropMode -> internalMove

    but there are two issue:

    • If the user drag an item within the table, it's allowed to drop it onto the top of another item: item will be lost. How could overwrite prevent?
    • I cannot find the proper signal, that I can use to get notification after an drag event. Which signal should I use?

    Regards,
    Norbert

    The solutuion:
    @
    Qt::ItemFlags customItemModel::flags(const QModelIndex& index) const {
    return index.isValid()? (base::flags(index) & ~Qt::ItemIsDropEnabled) : (base::flags(index) | Qt::ItemIsDropEnabled);
    }
    @

    and it works as I expect.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.