|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QComboBox
public class QComboBox
The QComboBox
widget is a combined button and popup list. 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.
Comboboxes can contain pixmaps as well as strings; the insertItem()
and setItemText()
functions are suitably overloaded. For editable comboboxes, the function clearEditText()
is provided, to clear the displayed string without changing the combobox's contents.
There are two signals emitted if the current item of a combobox changes, currentIndexChanged()
and activated()
. currentIndexChanged()
is always emitted regardless if the change was done programmatically or by user interaction, while activated()
is only emitted when the change is caused by user interaction. The highlighted()
signal is emitted when the user highlights an item in the combobox popup list. All three signals exist in two versions, one with a QString argument and one with an int argument. If the user selectes or highlights a pixmap, only the int signals are emitted. Whenever the text of an editable combobox is changed the editTextChanged()
signal is emitted.
When the user enters a new string in an editable combobox, the widget may or may not insert it, and it can insert it in several locations. The default policy is is AtBottom
but you can change this using setInsertPolicy()
.
It is possible to constrain the input to an editable combobox using QValidator
; see setValidator()
. By default, any input is accepted.
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()
. The text of the current item is returned by currentText()
, and the text of a numbered item is returned with text(). The current item can be set with setCurrentIndex()
. The number of items in the combobox is returned by count()
; the maximum number of items can be set with setMaxCount()
. You can allow editing using setEditable()
. For editable comboboxes you can set auto-completion using setCompleter()
and whether or not the user can add duplicates is set with setDuplicatesEnabled()
.
QComboBox
uses the model/view framework for its popup list and to store its items. By default a QStandardItemModel
stores the items and a QListView
subclass displays the popuplist. You can access the model and view directly (with model()
and view()
), but QComboBox
also provides functions to set and get item data (e.g., setItemData()
and itemText()
). You can also set a new model and view (with setModel()
and setView()
). For the text and icon in the combobox label, the data in the model that has the Qt::DisplayRole
and Qt::DecorationRole
is used.
QLineEdit
, QSpinBox
, QRadioButton
, QButtonGroup
, and GUI Design Handbook: Combo Box, Drop-Down List Box.
Nested Class Summary | |
---|---|
static class |
QComboBox.InsertPolicy
This enum specifies what the QComboBox should do when a new string is entered by the user. |
static class |
QComboBox.SizeAdjustPolicy
This enum specifies how the size hint of the QComboBox should adjust when new content is added or content changes. |
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Field Summary | |
---|---|
QSignalEmitter.Signal1 |
activated
This signal is sent when the user chooses an item in the combobox. |
QSignalEmitter.Signal1 |
activatedIndex
This signal is sent when the user chooses an item in the combobox. |
QSignalEmitter.Signal1 |
currentIndexChanged
This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. |
QSignalEmitter.Signal1 |
currentStringChanged
|
QSignalEmitter.Signal1 |
editTextChanged
This signal is emitted when the text in the combobox's line edit widget is changed. |
QSignalEmitter.Signal1 |
highlighted
This signal is sent when an item in the combobox popup list is highlighted by the user. |
QSignalEmitter.Signal1 |
highlightedIndex
This signal is sent when an item in the combobox popup list is highlighted by the user. |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Constructor Summary | |
---|---|
QComboBox()
Constructs a combobox with the given parent, using the default model QStandardItemModel . |
|
QComboBox(QWidget parent)
Constructs a combobox with the given parent, using the default model QStandardItemModel . |
Method Summary | |
---|---|
void |
addItem(QIcon icon,
java.lang.String text)
Adds an item to the combobox with the given icon and text, and containing the specified userData. |
void |
addItem(QIcon icon,
java.lang.String text,
java.lang.Object userData)
Adds an item to the combobox with the given icon and text, and containing the specified userData. |
void |
addItem(java.lang.String text)
Adds an item to the combobox with the given text, and containing the specified userData. |
void |
addItem(java.lang.String text,
java.lang.Object userData)
Adds an item to the combobox with the given text, and containing the specified userData. |
void |
addItems(java.util.List texts)
Adds each of the strings in the given texts to the combobox. |
void |
clear()
Clears the combobox, removing all items. |
void |
clearEditText()
Clears the contents of the line edit used for editing in the combobox. |
QCompleter |
completer()
Returns the completer that is used to auto complete text input for the combobox. |
int |
count()
This property holds the number of items in the combobox. |
int |
currentIndex()
This property holds the index of the current item in the combobox. |
java.lang.String |
currentText()
This property holds the text of the current item. |
boolean |
duplicatesEnabled()
This property holds whether the user can enter duplicate items into the combobox. |
int |
findData(java.lang.Object data)
Returns the index of the item containing the given data for the given role; otherwise returns -1. |
int |
findData(java.lang.Object data,
int role)
Returns the index of the item containing the given data for the given role; otherwise returns -1. |
int |
findData(java.lang.Object data,
int role,
Qt.MatchFlag[] flags)
Returns the index of the item containing the given data for the given role; otherwise returns -1. |
int |
findData(java.lang.Object data,
int role,
Qt.MatchFlags flags)
Returns the index of the item containing the given data for the given role; otherwise returns -1. |
int |
findText(java.lang.String text)
Returns the index of the item containing the given text; otherwise returns -1. |
int |
findText(java.lang.String text,
Qt.MatchFlag[] flags)
Returns the index of the item containing the given text; otherwise returns -1. |
int |
findText(java.lang.String text,
Qt.MatchFlags flags)
Returns the index of the item containing the given text; otherwise returns -1. |
static QComboBox |
fromNativePointer(QNativePointer nativePointer)
|
boolean |
hasFrame()
This property holds whether the combo box draws itself with a frame. |
void |
hidePopup()
Hides the list of items in the combobox if it is currently visible; otherwise this function does nothing. |
QSize |
iconSize()
This property holds the size of the icons shown in the combobox. |
protected void |
initStyleOption(QStyleOptionComboBox option)
Initialize option with the values from this QComboBox. |
void |
insertItem(int index,
QIcon icon,
java.lang.String text)
Inserts the icon, text and userData into the combobox at the given index. |
void |
insertItem(int index,
QIcon icon,
java.lang.String text,
java.lang.Object userData)
Inserts the icon, text and userData into the combobox at the given index. |
void |
insertItem(int index,
java.lang.String text)
Inserts the text and userData into the combobox at the given index. |
void |
insertItem(int index,
java.lang.String text,
java.lang.Object userData)
Inserts the text and userData into the combobox at the given index. |
void |
insertItems(int index,
java.util.List texts)
Inserts the strings from the list into the combobox as separate items, starting at the index specified. |
QComboBox.InsertPolicy |
insertPolicy()
This property holds the policy used to determine where user-inserted items should appear in the combobox. |
void |
insertSeparator(int index)
Inserts a separator item into the combobox at the given index. |
boolean |
isEditable()
This property holds whether the combobox can be edited by the user. |
java.lang.Object |
itemData(int index)
Returns the data for the given role in the given index in the combobox, or QVariant::Invalid if there is no data for this role. |
java.lang.Object |
itemData(int index,
int role)
Returns the data for the given role in the given index in the combobox, or QVariant::Invalid if there is no data for this role. |
QAbstractItemDelegate |
itemDelegate()
Returns the item delegate used by the popup list view. |
QIcon |
itemIcon(int index)
Returns the icon for the given index in the combobox. |
java.lang.String |
itemText(int index)
Returns the text for the given index in the combobox. |
QLineEdit |
lineEdit()
Returns the line edit used to edit items in the combobox, or 0 if there is no line edit. |
int |
maxCount()
This property holds the maximum number of items allowed in the combobox. |
int |
maxVisibleItems()
This property holds the maximum allowed size on screen of the combobox. |
int |
minimumContentsLength()
This property holds the minimum number of characters that should fit into the combobox. |
QAbstractItemModel |
model()
Returns the model used by the combobox. |
int |
modelColumn()
This property holds the column in the model that is visible. |
void |
removeItem(int index)
Removes the item at the given index from the combobox. |
QModelIndex |
rootModelIndex()
Returns the root model item index for the items in the combobox. |
void |
setCompleter(QCompleter c)
Sets the completer to use instead of the current completer. |
void |
setCurrentIndex(int index)
This property holds the index of the current item in the combobox. |
void |
setDuplicatesEnabled(boolean enable)
This property holds whether the user can enter duplicate items into the combobox. |
void |
setEditable(boolean editable)
This property holds whether the combobox can be edited by the user. |
void |
setEditText(java.lang.String text)
Sets the text in the combobox's text edit. |
void |
setFrame(boolean arg__1)
This property holds whether the combo box draws itself with a frame. |
void |
setIconSize(QSize size)
This property holds the size of the icons shown in the combobox. |
void |
setInsertPolicy(QComboBox.InsertPolicy policy)
This property holds the policy used to determine where user-inserted items should appear in the combobox. |
void |
setItemData(int index,
java.lang.Object value)
Sets the data role for the item on the given index in the combobox to the specified value. |
void |
setItemData(int index,
java.lang.Object value,
int role)
Sets the data role for the item on the given index in the combobox to the specified value. |
void |
setItemDelegate(QAbstractItemDelegate delegate)
Sets the item delegate for the popup list view. |
void |
setItemIcon(int index,
QIcon icon)
Sets the icon for the item on the given index in the combobox. |
void |
setItemText(int index,
java.lang.String text)
Sets the text for the item on the given index in the combobox. |
void |
setLineEdit(QLineEdit edit)
Sets the line edit to use instead of the current line edit widget. |
void |
setMaxCount(int max)
This property holds the maximum number of items allowed in the combobox. |
void |
setMaxVisibleItems(int maxItems)
This property holds the maximum allowed size on screen of the combobox. |
void |
setMinimumContentsLength(int characters)
This property holds the minimum number of characters that should fit into the combobox. |
void |
setModel(QAbstractItemModel model)
Sets the model to be model. |
void |
setModelColumn(int visibleColumn)
This property holds the column in the model that is visible. |
void |
setRootModelIndex(QModelIndex index)
Sets the root model item index for the items in the combobox. |
void |
setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy policy)
This property holds the policy describing how the size of the combobox changes when the content changes. |
void |
setValidator(QValidator v)
Sets the validator to use instead of the current validator. |
void |
setView(QAbstractItemView itemView)
Sets the view to be used in the combobox popup to the given itemView. |
void |
showPopup()
Displays the list of items in the combobox. |
QComboBox.SizeAdjustPolicy |
sizeAdjustPolicy()
This property holds the policy describing how the size of the combobox changes when the content changes. |
QValidator |
validator()
Returns the validator that is used to constrain text input for the combobox. |
QAbstractItemView |
view()
Returns the list view used for the combobox popup. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1 activated
currentIndexChanged()
.
public final QSignalEmitter.Signal1 activatedIndex
currentIndexChanged()
.
public final QSignalEmitter.Signal1 currentStringChanged
public final QSignalEmitter.Signal1 currentIndexChanged
currentIndex
in the combobox changes either through user interaction or programmatically. The item's index is passed or -1 if the combobox becomes empty or the currentIndex
was reset.
public final QSignalEmitter.Signal1 editTextChanged
public final QSignalEmitter.Signal1 highlighted
public final QSignalEmitter.Signal1 highlightedIndex
Constructor Detail |
---|
public QComboBox()
QStandardItemModel
.
public QComboBox(QWidget parent)
QStandardItemModel
.
Method Detail |
---|
public final void addItem(QIcon icon, java.lang.String text)
public final void addItem(QIcon icon, java.lang.String text, java.lang.Object userData)
public final void addItem(java.lang.String text)
public final void addItem(java.lang.String text, java.lang.Object userData)
public final void addItems(java.util.List texts)
public final void clear()
Note: If you have set an external model on the combobox this model will still be cleared when calling this function.
public final void clearEditText()
public final QCompleter completer()
setCompleter()
, and editable
.
public final int count()
public final int currentIndex()
public final java.lang.String currentText()
public final boolean duplicatesEnabled()
public final int findData(java.lang.Object data, int role, Qt.MatchFlag[] flags)
The flags specify how the items in the combobox are searched.
public final int findData(java.lang.Object data, int role)
The flags specify how the items in the combobox are searched.
public final int findData(java.lang.Object data)
The flags specify how the items in the combobox are searched.
public final int findData(java.lang.Object data, int role, Qt.MatchFlags flags)
The flags specify how the items in the combobox are searched.
public final int findText(java.lang.String text, Qt.MatchFlag[] flags)
The flags specify how the items in the combobox are searched.
public final int findText(java.lang.String text)
The flags specify how the items in the combobox are searched.
public final int findText(java.lang.String text, Qt.MatchFlags flags)
The flags specify how the items in the combobox are searched.
public final boolean hasFrame()
public final QSize iconSize()
public final void insertItem(int index, QIcon icon, java.lang.String text)
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
insertItems()
.
public final void insertItem(int index, QIcon icon, java.lang.String text, java.lang.Object userData)
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
insertItems()
.
public final void insertItem(int index, java.lang.String text)
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
insertItems()
.
public final void insertItem(int index, java.lang.String text, java.lang.Object userData)
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
insertItems()
.
public final void insertItems(int index, java.util.List texts)
If the index is equal to or higher than the total number of items, the new items are appended to the list of existing items. If the index is zero or negative, the new items are prepended to the list of existing items.
insertItem()
.
public final QComboBox.InsertPolicy insertPolicy()
AtBottom
, indicating that new items will appear at the bottom of the list of items. InsertPolicy
.
public final void insertSeparator(int index)
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
insertItem()
.
public final boolean isEditable()
public final java.lang.Object itemData(int index)
QVariant::Invalid
if there is no data for this role. setItemData()
.
public final java.lang.Object itemData(int index, int role)
QVariant::Invalid
if there is no data for this role. setItemData()
.
public final QAbstractItemDelegate itemDelegate()
setItemDelegate()
.
public final QIcon itemIcon(int index)
setItemIcon()
.
public final java.lang.String itemText(int index)
setItemText()
.
public final QLineEdit lineEdit()
Only editable combo boxes have a line edit.
setLineEdit()
.
public final int maxCount()
public final int maxVisibleItems()
public final int minimumContentsLength()
If this property is set to a positive value, the minimumSizeHint()
and sizeHint()
take it into account.
sizeAdjustPolicy
.
public final QAbstractItemModel model()
setModel()
.
public final int modelColumn()
public final void removeItem(int index)
public final QModelIndex rootModelIndex()
setRootModelIndex()
.
public final void setCompleter(QCompleter c)
By default, for an editable combo box, a QCompleter
that performs case insensitive inline completion is automatically created.
completer()
.
public final void setCurrentIndex(int index)
public final void setDuplicatesEnabled(boolean enable)
public final void setEditText(java.lang.String text)
public final void setEditable(boolean editable)
public final void setFrame(boolean arg__1)
public final void setIconSize(QSize size)
public final void setInsertPolicy(QComboBox.InsertPolicy policy)
AtBottom
, indicating that new items will appear at the bottom of the list of items. InsertPolicy
.
public final void setItemData(int index, java.lang.Object value)
itemData()
.
public final void setItemData(int index, java.lang.Object value, int role)
itemData()
.
public final void setItemDelegate(QAbstractItemDelegate delegate)
Warning: You should not share the same instance of a delegate between comboboxes, widget mappers or views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the closeEditor()
signal, and attempt to access, modify or close an editor that has already been closed.
itemDelegate()
.
public final void setItemIcon(int index, QIcon icon)
itemIcon()
.
public final void setItemText(int index, java.lang.String text)
itemText()
.
public final void setLineEdit(QLineEdit edit)
The combo box takes ownership of the line edit.
lineEdit()
.
public final void setMaxCount(int max)
public final void setMaxVisibleItems(int maxItems)
public final void setMinimumContentsLength(int characters)
If this property is set to a positive value, the minimumSizeHint()
and sizeHint()
take it into account.
sizeAdjustPolicy
.
public final void setModel(QAbstractItemModel model)
clear()
. model()
, and clear()
.
public final void setModelColumn(int visibleColumn)
public final void setRootModelIndex(QModelIndex index)
rootModelIndex()
.
public final void setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy policy)
AdjustToContentsOnFirstShow
. SizeAdjustPolicy
.
public final void setValidator(QValidator v)
validator()
.
public final void setView(QAbstractItemView itemView)
Note: If you want to use the convenience views (like QListWidget
, QTableWidget
or QTreeWidget
), make sure to call setModel()
on the combobox with the convenience widgets model before calling this function.
view()
.
public final QComboBox.SizeAdjustPolicy sizeAdjustPolicy()
AdjustToContentsOnFirstShow
. SizeAdjustPolicy
.
public final QValidator validator()
setValidator()
, and editable
.
public final QAbstractItemView view()
setView()
.
public void hidePopup()
public void showPopup()
public static QComboBox fromNativePointer(QNativePointer nativePointer)
protected final void initStyleOption(QStyleOptionComboBox option)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |