getting 'QTableWidget.setModel() is a private method'
-
Hi
I am attempting to make a page using Qt Designer with a two column table. One of the columns will be a drag and drop from a windows file listing and the second column is one of the Metafile items from the dropped file. The files are .mp3 and .wmf files and the Metafile item is comment. The file is then sent to QMediaPlayer. I am getting the message ‘QTableWidget.setModel() is a private method’. I would appreciate some insite, and a suggested correction.
Thank Youclass PlayTableModel(QAbstractTableModel):
def init(self, playlist, *args, **kwargs):
super(PlayTableModel, self).init(*args, **kwargs)
self.playlist = playlistdef data(self, index, role): if role == Qt.DisplayRole: media = self.playlist.media(index.row()) return media.canonicalUrl().fileName() def rowCount(self, index): return self.playlist.mediaCount()
class MainWindow(QMainWindow, Ui_MainWindow):
def init(self, *args, **kwargs):
super(MainWindow, self).init(*args, **kwargs)
self.setupUi(self)
self.player = QMediaPlayer()
self.player.error.connect(self.erroralert)
self.player.play()
# Setup the playlist.
self.playlist = QMediaPlaylist()
self.player.setPlaylist(self.playlist)# Connect control buttons/slides for media player. self.playButton.pressed.connect(self.player.play) self.pauseButton.pressed.connect(self.player.pause) self.stopButton.pressed.connect(self.player.stop) self.volumeSlider.valueChanged.connect(self.player.setVolume) self.clockButton.toggled.connect(self.toggle_clock) self.changeDanceStyleButton.toggled.connect(self.change_ds) # self.clock.state.connect(self.clockButton.setChecked) self.previousButton.pressed.connect(self.playlist.previous) self.nextButton.pressed.connect(self.playlist.next) self.model = PlayTableModel(self.playlist)
next line gets error QTableWidget.setModel() is a private method
self.playTableView.setModel(self.model) self.playlist.currentIndexChanged.connect(self.playTable_position_changed) selection_model = self.playTableView.selectionModel() selection_model.selectionChanged.connect(self.playTable_selection_changed) self.player.durationChanged.connect(self.update_duration) self.player.positionChanged.connect(self.update_position) self.timeSlider.valueChanged.connect(self.player.setPosition) self.open_file_action.triggered.connect(self.open_file) self.setAcceptDrops(True) self.show()
-
@Retired-Coder
Please use the forum's Code tag (</>
icon) to format blocks of code, especially for Python.Precisely because
QTableWidget
is aQTableView
plus an internal model for you to use but not change. Assuming yourplayTableView
really is aQTableWidget
per your topic question and not aQTableView
per its name....https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QTableWidget.html#detailed-description
If you want a table that uses your own data model you should use QTableView rather than this class.
Use a
QTableView
if you want to supply your own model.