PyQT5 compatibility issue: saving data from pyqtgraph.widgets.TableWidget

58 views
Skip to first unread message

Thomas Schultz

unread,
Mar 31, 2017, 4:20:11 AM3/31/17
to pyqtgraph
The save method in TableWidget.py is not compatible with PyQt5, because QtGui.QFileDialog.getSaveFileName returns a tuple.
This can be fixed by modifying the save method (see snippet below). Is there a way to have simultaneous compatibility with PyQt4 and PyQt5?

class MyTableWidget(pyqtgraph.TableWidget):
    
    def save(self, data):
        """ Overload save routine to make it PyQt5 compatible. """
        fileName, _ = QtGui.QFileDialog.getSaveFileName(self, "Save As..", "", "Tab-separated values (*.tsv)")
        if fileName == '':
            return
        open(fileName, 'w').write(data)

Sebastian Höfer

unread,
Mar 31, 2017, 5:11:43 AM3/31/17
to pyqtgraph
Hi Thomas,

for compatibility between PyQt4 and PySide I always used this expression:

filename = QtGui.QFileDialog.getSaveFileName( ...)
if isinstance(filename, tuple):
    filename = filename[0]
if filename == '':
   ...

That should work here, too.

Cheers
Sebastian
Reply all
Reply to author
Forward
0 new messages