How can I replace a custom delegate with the default delegate.



  • I'm successfully using QTableView::setItemDelegateForColumn to use a QDateTimeEdit widget to display and edit SQLite INTEGERs etc as dates and times.

    However I also need the ability to replace my custom delegate with the default delegate. However I can't see any obvious way of doing this: QAbstractItemDelegate::deleteLater() is the nearest method I could find.



  • In what way do you want to do the replacement? Do you mean that you want to switch input method while editing the item? Or do you mean something else? Please elaborate a bit on what you want to achieve.



  • I've created a context menu for the table header, so that for each column the user can choose to display and edit the content as a date, as a time, both, or natively. This is necessary because it's not possible from a general SQLite database to know how the data should be represented.

    The user should be able to open a view on a table, choose a delegate for a column, make some changes to the column, change the delegate, make some more changes. They should be able to submit the changes at any point.

    I can change delegates, but what I can't see how to do is revert to the default delegate so that the user can edit the "raw" or native data.



  • That clears it up, thank you.
    Not entirely sure, but you could try to set 0 as the column delegate? I think this should be documented in QAbstractItemView, but it is not.



  • that should work. If there is no column delegate, the main delegate is used.

    But take care of deleting the dlegates or give them the correct parents, otherwise you get a memory leak. The view dos not delete the old delegate on setItem...Delegate().



  • Setting the the delegate to NULL in QTableView::setItemDelegateForColumn() seems to do the trick.

    I've raised a bug report on the documentation to the effect that setting to NULL sets the default delegate.



  • Perhaps it would be helpful to link to the jira report here (and back?). You could do that with a bug-#### tag, if you like.




Log in to reply
 

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