Hello,

So I am switching a gui I have from using the QTable Widget to using a table view. I had a context menu on the old gui where I just added actions and had those actions connected to slots. When I moved over to a view/model approch I was left not really sure how I should implement. I started by adding the actions to the Model but then discovered that the model had no way to tell what the current index is so then I ended up moving them to the Mainform but that just doesn't seem right because to get to the current index I need the context slot function to be defined in the MainForm. I am just looking for any obvious do's or don'ts I am missing I am relativly new to GUI design below is and example of what I currently have.
Qt Code:
  1. class MainForm(QtGui.QDialog):
  2. super(MainForm, self).__init__(parent)
  3.  
  4. self.dataset = dmeta()
  5. self.tablemodel = MetaTableModel(self.dataset)
  6. self.tv = QtGui.QTableView()
  7. self.tv.setModel(self.tablemodel)
  8.  
  9. self.cAddColumn = QtGui.QAction('Insert Column',self.tv)
  10. self.cAddColumn.triggered.connect(self.contextAddColumn)
  11. self.tv.addAction(self.cAddColumn)
  12. self.cRemoveColumn = QtGui.QAction('Remove Column',self.tv)
  13. self.cRemoveColumn.triggered.connect(self.contextRemoveColumn())
  14. self.tv.addAction(self.cRemoveColumn)
  15.  
  16. def contextAddColumn(self,index):
  17. pass # Add column in the appropriate spot
  18.  
  19. def contextRemoveColumn(self,index):
  20. pass # Remove column in the appropriate spot
To copy to clipboard, switch view to plain text mode