class KComboBox


Module kdeui
Namespace
Class KComboBox
Inherits QComboBox,KCompletionBase
An enhanced combo box.

A combined button, line-edit and a popup list widget.

Detail \n

This widget inherits from QComboBox and implements the following additional functionalities: a completion object that provides both automatic and manual text completion as well as text rotation features, configurable key-bindings to activate these features, and a popup-menu item that can be used to allow the user to change the text completion mode on the fly.

To support these new features KComboBox emits a few additional signals such as completion( const QString& ) and textRotation( KeyBindingType ). The completion signal can be connected to a slot that will assist the user in filling out the remaining text while the rotation signal can be used to traverse through all possible matches whenever text completion results in multiple matches. Additionally, a returnPressed() and a returnPressed( const QString& ) signals are emitted when the user presses the Enter/Return key.

KCombobox by default creates a completion object when you invoke the completionObject( bool ) member function for the first time or explicitly use setCompletionObject( KCompletion*, bool ) to assign your own completion object. Additionally, to make this widget more functional, KComboBox will by default handle text rotation and completion events internally whenever a completion object is created through either one of the methods mentioned above. If you do not need this functionality, simply use KCompletionBase.setHandleSignals(bool) or alternatively set the boolean parameter in the setCompletionObject call to false.

Beware: The completion object can be deleted on you, especially if a call such as setEditable(false) is made. Store the pointer at your own risk, and consider using QGuardedPtr.

The default key-bindings for completion and rotation is determined from the global settings in KStandardShortcut. These values, however, can be overridden locally by invoking KCompletionBase.setKeyBinding(). The values can easily be reverted back to the default setting, by simply calling useGlobalSettings(). An alternate method would be to default individual key-bindings by usning setKeyBinding() with the default second argument.

A non-editable combobox only has one completion mode, CompletionAuto. Unlike an editable combobox the CompletionAuto mode, works by matching any typed key with the first letter of entries in the combobox. Please note that if you call setEditable( false ) to change an editable combobox to a non-editable one, the text completion object associated with the combobox will no longer exist unless you created the completion object yourself and assigned it to this widget or you called setAutoDeleteCompletionObject( false ). In other words do not do the following:

KComboBox* combo = new KCompletionBox(true, this);
KCompletion* comp = combo->completionObject();
combo->setEditable( false );
comp->clear(); // CRASH: completion object does not exist anymore.

A read-only KComboBox will have the same background color as a disabled KComboBox, but its foreground color will be the one used for the read-write mode. This differs from QComboBox's implementation and is done to give visual distinction between the three different modes: disabled, read-only, and read-write.

Usage \n

To enable the basic completion feature:

KComboBox *combo = new KComboBox( true, this );
KCompletion *comp = combo->completionObject();
// Connect to the return pressed signal - optional
connect(combo,SIGNAL(returnPressed(const QString&)),comp,SLOT(addItem(const QString&)));

// Provide the to be completed strings. Note that those are separate from the combo's // contents. comp->insertItems( someQStringList );

To use your own completion object:

KComboBox *combo = new KComboBox( this );
KUrlCompletion *comp = new KUrlCompletion();
combo->setCompletionObject( comp );
// Connect to the return pressed signal - optional
connect(combo,SIGNAL(returnPressed(const QString&)),comp,SLOT(addItem(const QString&)));

Note that you have to either delete the allocated completion object when you don't need it anymore, or call setAutoDeleteCompletionObject( true );

Miscellaneous function calls:

// Tell the widget not to handle completion and rotation
combo->setHandleSignals( false );
// Set your own completion key for manual completions.
combo->setKeyBinding( KCompletionBase.TextCompletion, Qt.End );

Author Dawit Alemayehu



methods