QComboBox.setPlaceholderText() 不工作

QComboBox.setPlaceholderText() not working

我目前正在尝试对广泛使用 qtpy 的 GUI 应用程序进行一些更改。对于特定条件,组合框的文本将设置为特定值。

为此我使用了 self.colormapComboBox.setPlaceholderText("RGB"),其中 colormapComboBox 是 class qtpy.QtWidgets.QComboBox 的一个对象。参考文档:this

导致错误:

AttributeError: 'QComboBox' object has no attribute 'setPlaceholderText'

如何解决这个问题?

首先使您的组合框可编辑。然后你需要使用这行代码。 self.colormapComboBox.lineEdit().setPlaceholderText("RGB")