Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Pyqt QAbstractTableModel remove all table rows
Forum Updated to NodeBB v4.3 + New Features

Pyqt QAbstractTableModel remove all table rows

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 4.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tobbyd
    wrote on last edited by
    #1

    I'm using a QtableView and I set the model to be my subclassed QAbstractTableModel.
    I'm searching a database and I would like to present the results in the QtableView.
    Everything works but for each row the new search results are added to a new row in the table.
    For each search I would like to completely clear the QtableView/QAbstractTableModel and only present the latest search results.

    I have tried every possible example that I can find online but I cant figure it out.
    How can I completely clear the QtableView/QAbstractTableModel?

    Thanks

    Below is my subclassed QAbstractTableModel :
    @

    class SearchModel(QtCore.QAbstractTableModel):

    def __init__(self,searchWin,  entrys=[[]],headers=[], parent=None):
        QtCore.QAbstractTableModel.__init__(self,parent)
        
        self.entrys = entrys
        self.headers = headers
        self.searchWindow = searchWin
        
    
        
        
    #HAS TO BE IMPLEMENTED IN A MODEL  
    def data(self,index,role):
        
        if role == QtCore.Qt.DisplayRole:
            
            row = index.row()
            column = index.column()
            value = self.entrys[row][column]
            
            return value
        
        if role == QtCore.Qt.EditRole:
            row = index.row()
            column = index.column()
            return self.entrys[row][column]
        
        if role == QtCore.Qt.ToolTipRole:
            row = index.row()
            column = index.column()
            
            
            
            if self.searchWindow.searchPresetsOnly:
                
                tt = "click to load this preset"
            else:
                tt = str(self.entrys[row][column])
            
            return  tt
    
    #HAS TO BE IMPLEMENTED IN A MODEL  DATA FOR EACH ROWCOUNT
    def rowCount(self,parent):
        return len(self.entrys)
    
    def columnCount(self,parent):
        
        return len(self.entrys[0])
    
    def flags(self, index):
        return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
    
    
    def headerData(self, section, orientation, role):
        
        if role == QtCore.Qt.DisplayRole:
            
            
            
            if orientation == QtCore.Qt.Horizontal: 
                
                
                #print(section)
               
                return QtCore.QString(self.headers[section])
                
                
            else:
                return QtCore.QString("Select")
    

    @

    [Edit: Added @ tags around code -- mlong]

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved