'selectedFilters' is not a valid keyword argument

痞子三分冷 提交于 2019-12-04 15:48:28

For various reasons, the C++ signatures don't always exactly match the PyQt signatures. This is probably the biggest weakness of PyQt5. There really needs to be a comprehensive reference that details all the differences between the C++ APIs and the PyQt APIs. It sort of exists for PyQt4, in the form of the PyQt Class Reference (which is a partially converted version of the Qt documentation). But there is currently nothing equivalent to that for PyQt5. However, you can always use python's introspection methods to work out the differences for yourself.

Here's the C++ signature for getSaveFileName:

QString getSaveFileName(QWidget *parent = Q_NULLPTR,
                        const QString &caption = QString(),
                        const QString &dir = QString(),
                        const QString &filter = QString(),
                        QString *selectedFilter = Q_NULLPTR,
                        Options options = Options()
                        )

And here's the PyQt5 signature, which was obtained from the help function in a python interactive session - i.e. help(QtWidgets.QFileDialog.getSaveFileName):

getSaveFileName(parent: QWidget = None,
                caption: str = '',
                directory: str = '',
                filter: str = '',
                initialFilter: str = '',
                options: Union[QFileDialog.Options, QFileDialog.Option] = 0,
                ) -> Tuple[str, str]

As you can see, the dir argument has changed to directory, and the selectedFilter argument has changed to initialFilter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!