In Qt 5.15 the placeholderText
property was introduced - link to documentation
However using setPlaceholderText
doesn't do anything for me. When running the code below i don't get any text in the QComboBox
(unless of course i select one of the three items)
Is this a bug or am i missing something? How can i make this work?
import sys
from PyQt5 import QtWidgets
from PyQt5 import QtCore
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
central_w = QtWidgets.QWidget()
self.setCentralWidget(central_w)
vbox = QtWidgets.QVBoxLayout()
central_w.setLayout(vbox)
self.combo_box = QtWidgets.QComboBox()
self.combo_box.addItems(["one", "two", "three"])
self.combo_box.setPlaceholderText("Some placeholder text here")
self.combo_box.setCurrentIndex(-1)
vbox.addWidget(self.combo_box)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
app.exec_()
I have found no way of showing the placeholder text. I've tried having no items at all in the combo box but even this doesn't show the placeholder text
These are the versions i am running:
- Qt: 5.15.2
- PyQt (Python module) version: 5.15.2 (this happens to be the same as the Qt version but can sometimes differ slightly)
- Python: "3.8.5 (default, Jul 28 2020, 12:59:40) \n[GCC 9.3.0]"
- OS: Ubuntu 20.04.1 LTS (with Xfce)
PS: If you want to achieve a similar effect (that is: having a text on a clickable area which shows a drop-down with different options after being clicked) you can use a QPushButton
with the setMenu
function. Documentation: https://doc.qt.io/qt-5/qpushbutton.html#setMenu