0

I'm working on a simple dialog to show a table with some editing controls in the cells. The dialog class was created in QtCreator and then converted into python. I then set up a 'main' window that initializes and displays an instance of the dialog. If I run that file, the dialog displays and everything looks good.

The trouble comes when I want to work with a custom table. I have a custom implementation of QTableView that looks like this:

from PyQt5 import QtCore
import PyQt5.Qt as qt

class GemTableView(qt.QTableView):
    '''
    classdocs
    '''


    def __init__(self,  *args, **kwargs):
        '''
        Constructor
        '''
        qt.QTableView.__init__(self,  *args, **kwargs)
        self.setItemDelegateForColumn(0, ComboDelegate(self))


class ComboDelegate(qt.QItemDelegate):
    #do some delegate things here
    pass
   

In my main window I initialize the UI and assign an instance of my table view to the existing table element:

class GemWindow(QtWidgets.QMainWindow, Ui_Dialog):
    '''
    classdocs
    '''


    def __init__(self, *args, obj=None, **kwargs):
        '''
        Constructor
        '''
        QtWidgets.QMainWindow.__init__(self)
        Ui_Dialog.__init__(self)
        
        self.setupUi(self)
        self.players = []
        self.gameActions = GameActions(["p1", "p2", "p3", "p4"])
        
        gems = self.gameActions.game.availableGems
        tokenModel = TokenStoreModel(gems, [Color.WHITE, Color.BLUE, Color.GREEN, Color.RED, Color.BLACK])
        #assign the custom table element
        self.gemWithdrawTable = GemTableView(self.layoutWidget)
        self.gemWithdrawTable.setModel(tokenModel)
        
    def accept(self):
        pass
    
    def reject(self):
        pass

app = QtWidgets.QApplication(sys.argv)

window = GemWindow()
window.show()
app.exec()  

Now when I run my program, it appends a new table onto the displayed dialog rather than overwriting the existing table. Clearly I'm doing something wrong, but I can't seem to find any information about how to do this correctly. Is there any way to replace the generated table with my implementation or do I have to create the table from scratch in the code?

pbuchheit
  • 1,371
  • 1
  • 20
  • 47

0 Answers0