Results 1 to 7 of 7

Thread: editorEvent parent question

  1. #1
    Join Date
    Oct 2014
    Posts
    22
    Qt products
    Qt3 Qt4 Qt5 PyQt3 PyQt4

    Default editorEvent parent question

    Hi Everyone,

    I have a question with the editorEvent method. From my understanding this allows the QPushButton in the delegate to do something on the pushbutton event. This allows one to embed pushbuttons in a model and have the button do something. I am using a QtGui.QStyledItemDelegate and a QtCore.QAbstractItemModel. The goal is to make a tree of buttons and then have each button call a different script.

    How do you pass the self in the class though? I want the new window to be a child of the main dialog, but this is in the delegate class not the gui class. Self would be the delegate not the main window gui.

    How do you pass the parent widget in the delegate?
    Qt Code:
    1. def editorEvent(self, event, model, option, index):
    2. if event.type() == QtCore.QEvent.MouseButtonPress:
    3. if index.data() == "tool 2":
    4. self._o_grittool2 = tool2.Tool2(database=self._dbfname,
    5. plan_table="plan", cfr_table="cfr", parent=self)
    6. self._o_grittool2.exec_()
    7. tool_executed = True
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: editorEvent parent question

    You can pass the widget you want to be used as a parent as an additional constructor argument to the delegate.
    Or provide a setter method if the parent changes during the delegates life time.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2014
    Posts
    22
    Qt products
    Qt3 Qt4 Qt5 PyQt3 PyQt4

    Default Re: editorEvent parent question

    I see so I could pass the dialog in the delegate. What is a setter method?

    I did it with a signal and slot which seem to be working nicely.



    Qt Code:
    1. def editorEvent(self, event, model, option, index):
    2. """
    3. When editing of an item starts, this function is called with the event
    4. that triggered the editing, the model, the index of the item,
    5. and the option used for rendering the item.
    6.  
    7. Mouse events are sent to editorEvent() even if they don't start editing
    8. of the item. This can, for instance, be useful if you wish to open a
    9. context menu when the right mouse button is pressed on an item.
    10.  
    11. The base implementation returns false (indicating that it has not
    12. handled the event).
    13.  
    14. This is needed so when the createEditor is clicked then this is called.
    15. This actually opens the import spatial data dialog.
    16. """
    17. if event.type() == QtCore.QEvent.MouseButtonPress:
    18. self.button_signal.emit(index.row(), index.column())
    19. return True
    20. elif event.type() == QtCore.QEvent.MouseButtonRelease:
    21. return True
    22.  
    23. else:
    24. return super(IssueDelegate, self).editorEvent(event, model, option, index)
    25.  
    26. # signal
    27. self.delegate.button_signal.connect(self.importGIS)
    28.  
    29. def importGIS(self, val, val2):
    30. ## Instantiate the class.
    31. self.file_browser = importGIS.ImportGIS(db,
    32. title="Issues", fcType_filter=["Polyline", "Point", "Polygon"], sel_count="one", parent = self)
    33.  
    34. index = self.model.index(val, val2)
    35. # Execute the file dialog.
    36. # This will return the dialog to the user as a modal dialog.
    37. if self.file_browser.exec_():
    38. if self.file_browser.file_list_new > 0:
    39.  
    40. # Setdata method.
    41. self.model.setData(index, os.path.basename(self.file_browser.file_list_new[0]))
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: editorEvent parent question

    Quote Originally Posted by lukeQt View Post
    I see so I could pass the dialog in the delegate. What is a setter method?
    A "setter" is a method that changes the data of a specific field of the object.
    Usually in pair with a "getter", a method that returns the value of a field in the object.

    Something like
    Qt Code:
    1. def setDialogParent(self, dialogParent):
    2. self.dialogParent = dialogParent
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Oct 2014
    Posts
    22
    Qt products
    Qt3 Qt4 Qt5 PyQt3 PyQt4

    Default Re: editorEvent parent question

    Is using a signal slot a good approach to achieving what I want? It seems to be working.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: editorEvent parent question

    Yes, that looks fine as well.

    Cheers,
    _

  7. #7
    Join Date
    Oct 2014
    Posts
    22
    Qt products
    Qt3 Qt4 Qt5 PyQt3 PyQt4

    Default Re: editorEvent parent question

    Thank you anda_skoa!!

Similar Threads

  1. Replies: 0
    Last Post: 7th August 2013, 16:27
  2. Crash in editorEvent with a delete key press event
    By xiangyu in forum Qt Programming
    Replies: 0
    Last Post: 26th March 2013, 15:57
  3. QModelIndex::parent question
    By QPlace in forum Qt Programming
    Replies: 4
    Last Post: 26th June 2009, 12:26
  4. QWidget *parent = 0 question
    By radek.z in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2009, 09:32
  5. QItemDelegate::editorEvent
    By jml in forum Qt Programming
    Replies: 1
    Last Post: 13th February 2008, 00:26

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.