Results 1 to 4 of 4

Thread: how to manually call an instance of QStyledItemDelegate

  1. #1
    Join Date
    Mar 2011
    Posts
    25
    Thanks
    7
    Qt products
    Qt4

    Default how to manually call an instance of QStyledItemDelegate

    I'm using a QStyledItemDelegate to edit the text of a QTreeWidgetItem when I double click on it.
    Now I want the same functionality (renaming the item) when the user selects it through the context menu of the treewidget item.

    Is it possible to call the createEditor() function of the delegate when the user selects the option through the context menu?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to manually call an instance of QStyledItemDelegate

    Isn't it easier to just call QAbstractItemView::edit()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2011
    Posts
    25
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to manually call an instance of QStyledItemDelegate

    Quote Originally Posted by wysota View Post
    Isn't it easier to just call QAbstractItemView::edit()?
    Do you mean instead of using the delegate? I need the delegate since I either create a custom button for children items or a line edit for all top-level items. Is there no way to manually use the delegate and call the create function when using the context menu and not a trigger option like double click?
    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to manually call an instance of QStyledItemDelegate

    The delegate is associated with a (subset of) view. If you call edit() on the view, the view will call createEditor() of the delegate associated with the index you want to edit.

    Is there no way to manually use the delegate and call the create function when using the context menu and not a trigger option like double click?
    Sure you can call it but then you'll just get a widget floating around somewhere and unrelated in any way to the item you want to edit. If you want to edit an item then call edit().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    iwatsu (2nd February 2012)

Similar Threads

  1. Replies: 80
    Last Post: 12th March 2020, 13:58
  2. How to manually pan canvas
    By novackb in forum Qwt
    Replies: 4
    Last Post: 18th February 2011, 17:46
  3. Can't manually update QGraphicsScene
    By aladagemre in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2010, 21:52
  4. Manually using RCC compiler?
    By vishal.chauhan in forum Qt Programming
    Replies: 2
    Last Post: 18th May 2007, 07:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.