Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setPlaceholderText for QComboBox [duplicate]

Tags:

c++

qt

Without subclassing can I have in QComboBox text that will be shown where no selection was made, something like setPlaceholderText in QLineEdit?

like image 563
Borrimoro Avatar asked Aug 16 '13 13:08

Borrimoro


People also ask

How do I add items to QComboBox?

A combobox can be populated using the insert functions, insertItem() and insertItems() for example. Items can be changed with setItemText(). An item can be removed with removeItem() and all items can be removed with clear().

What is a QComboBox?

A QComboBox provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space. A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable, allowing the user to modify each item in the list.


1 Answers

QComboBox does not have a placeholder text option but you can achieve this in two ways:

  1. 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.
  2. Use myCombo->lineEdit()->setPlaceholderText("Some text"); But this will only work if your combobox is editable.
like image 87
erelender Avatar answered Oct 13 '22 00:10

erelender