Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I replace a custom delegate with the default delegate.
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 9.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jonathan
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jonathan
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            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().

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jonathan
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  It's "QTBUG-16457":http://bugreports.qt.nokia.com/browse/QTBUG-16457

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved