Without subclassing can I have in QComboBox text that will be shown where no selection was made, something like setPlaceholderText in QLineEdit?
            Asked
            
        
        
            Active
            
        
            Viewed 1.1k times
        
    5
            
            
        - 
                    Possible Duplicate: http://stackoverflow.com/questions/6327964/qcombox-how-to-set-hint-text-on-combo-box – erelender Aug 16 '13 at 13:58
 - 
                    In my window ctor this works: `comboBox->setCurrentIndex(-1);` then I see place holder which I pick in Qt Designer – Gelldur Sep 02 '21 at 07:42
 
1 Answers
21
            QComboBox does not have a placeholder text option but you can achieve this in two ways:
- Add an item with your placeholder text as the first item in the combobox and handle the item selection to account for the extra item.
 - Use 
myCombo->lineEdit()->setPlaceholderText("Some text");But this will only work if your combobox is editable. 
- 
                    
 - 
                    One tiny thing I had to do to make option #2 work, is to do `setCurrentIndex(-1)`. Otherwise it was selecting one of the items by default, instead of showing the placeholder – Nico Villanueva Feb 08 '22 at 17:14