KUrlComboBox Class

This combobox shows a number of recent URLs/directories, as well as some default directories. More...

Header: #include <KUrlComboBox>
CMake: find_package(KF6 REQUIRED COMPONENTS KIO)
target_link_libraries(mytarget PRIVATE KF6::KIOWidgets)

Public Types

enum Mode { Files, Directories, Both }
enum OverLoadResolving { RemoveTop, RemoveBottom }

Properties

Public Functions

KUrlComboBox(KUrlComboBox::Mode mode, QWidget *parent = nullptr)
KUrlComboBox(KUrlComboBox::Mode mode, bool rw, QWidget *parent = nullptr)
void addDefaultUrl(const QUrl &url, const QString &text = QString())
void addDefaultUrl(const QUrl &url, const QIcon &icon, const QString &text = QString())
int maxItems() const
void removeUrl(const QUrl &url, bool checkDefaultURLs = true)
void setDefaults()
void setMaxItems(int)
void setUrl(const QUrl &url)
void setUrls(const QStringList &urls)
void setUrls(const QStringList &urls, KUrlComboBox::OverLoadResolving remove)
QStringList urls() const

Signals

void urlActivated(const QUrl &url)

Detailed Description

It will manage the default dirs root-directory, home-directory and Desktop-directory, as well as a number of URLs set via setUrls() and one additional entry to be set via setUrl().

This widget forces the layout direction to be Qt::LeftToRight instead of inheriting the layout direction like a normal widget. This means that even in RTL desktops the widget will be displayed in LTR mode, as generally URLs are LTR by nature.

Member Type Documentation

enum KUrlComboBox::Mode

This enum describes which kind of items is shown in the combo box.

ConstantValue
KUrlComboBox::Files-1
KUrlComboBox::Directories1
KUrlComboBox::Both0

enum KUrlComboBox::OverLoadResolving

This Enumeration is used in setUrl() to determine which items will be removed when the given list is larger than maxItems().

ConstantValueDescription
KUrlComboBox::RemoveTop0means that items will be removed from top
KUrlComboBox::RemoveBottom1means, that items will be removed from the bottom

Property Documentation

maxItems : int

Access functions:

int maxItems() const
void setMaxItems(int)

urls : QStringList

Access functions:

QStringList urls() const
void setUrls(const QStringList &urls)
void setUrls(const QStringList &urls, KUrlComboBox::OverLoadResolving remove)

Member Function Documentation

[explicit] KUrlComboBox::KUrlComboBox(KUrlComboBox::Mode mode, QWidget *parent = nullptr)

Constructs a KUrlComboBox.

mode is either Files, Directories or Both and controls the following behavior:

  • Files all inserted URLs will be treated as files, therefore the url shown in the combo will never show a trailing / the icon will be the one associated with the file's MIME type.
  • Directories all inserted URLs will be treated as directories, will have a trailing slash in the combobox. The current directory will show the "open folder" icon, other directories the "folder" icon.
  • Both Don't mess with anything, just show the url as given.

parent The parent object of this widget.

KUrlComboBox::KUrlComboBox(KUrlComboBox::Mode mode, bool rw, QWidget *parent = nullptr)

void KUrlComboBox::addDefaultUrl(const QUrl &url, const QString &text = QString())

Adds a url that will always be shown in the combobox, it can't be "rotated away". Default urls won't be returned in urls() and don't have to be set via setUrls().

If you want to specify a special pixmap, use the overloaded method with the pixmap parameter.

Default URLs will be inserted into the combobox by setDefaults()

void KUrlComboBox::addDefaultUrl(const QUrl &url, const QIcon &icon, const QString &text = QString())

Adds a url that will always be shown in the combobox, it can't be "rotated away". Default urls won't be returned in urls() and don't have to be set via setUrls().

If you don't need to specify a pixmap, use the overloaded method without the pixmap parameter.

Default URLs will be inserted into the combobox by setDefaults()

int KUrlComboBox::maxItems() const

Returns the maximum of items the combobox handles.

Note: Getter function for property maxItems.

See also setMaxItems.

void KUrlComboBox::removeUrl(const QUrl &url, bool checkDefaultURLs = true)

Removes any occurrence of url. If checkDefaultUrls is false default-urls won't be removed.

void KUrlComboBox::setDefaults()

Clears all items and inserts the default urls into the combo. Will be called implicitly upon the first call to setUrls() or setUrl()

See also addDefaultUrl.

void KUrlComboBox::setMaxItems(int)

Sets how many items should be handled and displayed by the combobox.

Note: Setter function for property maxItems.

See also maxItems.

void KUrlComboBox::setUrl(const QUrl &url)

Sets the current url. This combo handles exactly one url additionally to the default items and those set via setUrls(). So you can call setUrl() as often as you want, it will always replace the previous one set via setUrl().

If url is already in the combo, the last item will stay there and the existing item becomes the current item.

The current item will always have the open-directory-pixmap as icon.

Note that you won't receive any signals, e.g. textChanged(), returnPressed() or activated() upon calling this method.

void KUrlComboBox::setUrls(const QStringList &urls)

Inserts urls into the combobox below the "default urls" (see addDefaultUrl).

If the list of urls contains more items than maxItems, the first items will be stripped.

Note: Setter function for property urls.

See also urls().

void KUrlComboBox::setUrls(const QStringList &urls, KUrlComboBox::OverLoadResolving remove)

Inserts urls into the combobox below the "default urls" (see addDefaultUrl).

If the list of urls contains more items than maxItems, the remove parameter determines whether the first or last items will be stripped.

Note: Setter function for property urls.

[signal] void KUrlComboBox::urlActivated(const QUrl &url)

Emitted when an item was clicked at.

url is the url of the now current item.

QStringList KUrlComboBox::urls() const

Returns a list of all urls currently handled. The list contains at most maxItems() items.

Use this to save the list of urls in a config-file and reinsert them via setUrls() next time.

Note that all default urls set via addDefaultUrl() are not returned, they will automatically be set via setUrls() or setUrl().

You will always get fully qualified urls, i.e. with protocol like file:/

Note: Getter function for property urls.

See also setUrls().