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.
super(MainForm, self).__init__(parent)
self.dataset = dmeta()
self.tablemodel = MetaTableModel(self.dataset)
self.tv.setModel(self.tablemodel)
self.
cAddColumn = QtGui.
QAction('Insert Column',self.
tv) self.cAddColumn.triggered.connect(self.contextAddColumn)
self.tv.addAction(self.cAddColumn)
self.
cRemoveColumn = QtGui.
QAction('Remove Column',self.
tv) self.cRemoveColumn.triggered.connect(self.contextRemoveColumn())
self.tv.addAction(self.cRemoveColumn)
def contextAddColumn(self,index):
pass # Add column in the appropriate spot
def contextRemoveColumn(self,index):
pass # Remove column in the appropriate spot
class MainForm(QtGui.QDialog):
super(MainForm, self).__init__(parent)
self.dataset = dmeta()
self.tablemodel = MetaTableModel(self.dataset)
self.tv = QtGui.QTableView()
self.tv.setModel(self.tablemodel)
self.cAddColumn = QtGui.QAction('Insert Column',self.tv)
self.cAddColumn.triggered.connect(self.contextAddColumn)
self.tv.addAction(self.cAddColumn)
self.cRemoveColumn = QtGui.QAction('Remove Column',self.tv)
self.cRemoveColumn.triggered.connect(self.contextRemoveColumn())
self.tv.addAction(self.cRemoveColumn)
def contextAddColumn(self,index):
pass # Add column in the appropriate spot
def contextRemoveColumn(self,index):
pass # Remove column in the appropriate spot
To copy to clipboard, switch view to plain text mode
Bookmarks