Results 1 to 6 of 6

Thread: Tableview dialog as delegate

  1. #1
    Join Date
    Oct 2015
    Posts
    45
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Tableview dialog as delegate

    I am trying to create a button delegate in the first column of a tableview that launches a dialog to edit the data in the row of the button.

    I get the delegate button. But, since setEditorData is not called by the clicked event of the button, I don't see how to get the data to fill in on the dialog.

    I can't see that the clicked event has access to the index or the model.

    Can anyone give me some tips or point me to an example?

    All the examples I've found are either just creating a button delegate or a spin box for a particular cell of the table.

    Regards,
    Mac
    Last edited by drmacro; 25th October 2015 at 19:03.

  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: Tableview dialog as delegate

    Please verify that setEditorData() is not called at all, it should be called when the cell becomes editable and when the cell contents change while it is editable.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2015
    Posts
    45
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Tableview dialog as delegate

    Well I have print statements in setEditorData(). They only print when each of the delegate buttons gets created.

    But, not when I click the button.

  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: Tableview dialog as delegate

    Why would the setEditorData() method be called when you click the button?

    Clicking the button doesn't change anything in the model, does it?
    The data didn't change since the last time the delegate was informed about data change.
    So why would the view need to call setEditorData() again?

    How does your slot look like that you have connected to the button's clicked() signal?

    Cheers,
    _

  5. #5
    Join Date
    Oct 2015
    Posts
    45
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Tableview dialog as delegate

    Don't know why my earlier reply didn't show up...

    The clicked() code is like this at the moment.

    This launches the dialog, but, I don't know how to get the row data from the delegate button.

    Qt Code:
    1. def currentIndexChanged(self):
    2. sndr = self.sender()
    3. print("Button Clicked: " + str(sndr.text()))
    4.  
    5. self.editcuedlg = EditCue(str(sndr.text()))
    6. self.editcuedlg.exec_()
    7. #self.commitData.emit(self.sender())
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Mac


    Added after 42 minutes:


    I'm having a hard time getting the big picture of how the model/view/delegate process works...that may be most of my problem.

    In the Qt doc example of delegates it says: "The createEditor() function is called when the user starts editing an item..."

    I build the gui with:

    Qt Code:
    1. if __name__ == '__main__':
    2.  
    3. app = QApplication(sys.argv)
    4. ex = Example()
    5. ex.disptext()
    6. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    ex.disptext() does this:

    Qt Code:
    1. def disptext(self):
    2. self.get_table_data()
    3. # set the table model
    4. header = ['','Cue Number', 'Act', 'Scene', 'Page', 'ID', 'Title','Dialog/Prompt']
    5. tablemodel = MyTableModel(self.tabledata, header, self.tv)
    6. self.tv.setModel(tablemodel)
    7. self.tv.resizeColumnsToContents()
    8. for row in range(0, tablemodel.rowCount(tablemodel)):
    9. self.tv.openPersistentEditor(tablemodel.index(row, 0))
    To copy to clipboard, switch view to plain text mode 

    So if if there are 106 rows in the data, createEditor() in the delegate code gets called 106 times, but not later when the user clicks the button delegate.:

    Qt Code:
    1. class theDelegate(QStyledItemDelegate):
    2. """
    3. """
    4. def __init__(self, parent):
    5. # The parent is not an optional argument for the delegate as
    6. # we need to reference it in the paint method (see below)
    7. QStyledItemDelegate.__init__(self, parent)
    8.  
    9.  
    10. def createEditor(self, parent, option, index):
    11. editDlg = QPushButton("x" + str(index.row()), parent)
    12. editDlg.blockSignals(True)
    13. editDlg.clicked.connect(self.rowButtonClicked)
    14. editDlg.blockSignals(False)
    15. print("createEditor, index = " + str(index.row()))
    16. return editDlg
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Mac
    Last edited by drmacro; 27th October 2015 at 23:00.

  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: Tableview dialog as delegate

    Both in createEditor() as well as in setModelData() you get the model index of the cell.
    Since you are only interested in the row, you just store the row, e.g. using setProperty() on the button or a QSignalMapper
    The you either get the data for the row when you open the dialog or you pass the row and the model to the dialog and let it retrieve the data itself.

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    drmacro (28th November 2015)

Similar Threads

  1. Issue with custom delegate in tableview
    By alizadeh91 in forum Qt Programming
    Replies: 4
    Last Post: 13th April 2013, 08:39
  2. Button Delegate Problem in TableView
    By alizadeh91 in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2013, 17:13
  3. Replies: 4
    Last Post: 22nd September 2010, 22:34
  4. Replies: 14
    Last Post: 19th March 2007, 08:48
  5. TableView Delegate questions
    By No-Nonsense in forum Qt Programming
    Replies: 3
    Last Post: 11th December 2006, 09:39

Tags for this Thread

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.