QComboBox - How to set tooltip text in combo box

For the graphical interface of the application for which I work, the user needs a combo box. When the application starts, the combo box displays a hint text, for example, "Please select", and does not show the first element of the combo box. I can not find any method for setting tooltip text in http://doc.qt.io/qt-5/qcombobox.html#currentText-prop .

Thanks in advance!

+3
source share
2 answers

There is an elegant solution if QComboBoxthere is editable:

myQComboBox->lineEdit()->setPlaceHolderText("Please select");

QComboBoxes that are not are editablenot in them QLineEdit, so this will not work for them.

+4

QComboBox. . setEditText( const QString& ) . comboBox, . , ( ), . , QComboBox focusOutEvent(...), : if ( currentIndex() == -1 ) setEditText( tr( "Please select" ) );. QComboBox::focusOutEvent(...).

+1

All Articles