KUrlRequester Class

A widget to request a filename/url from the user. More...

Header: #include <KUrlRequester>
CMake: find_package(KF6 REQUIRED COMPONENTS KIO)
target_link_libraries(mytarget PRIVATE KF6::KIOWidgets)
Inherits: QWidget
Inherited By:

KUrlComboRequester

Properties

Public Functions

KUrlRequester(QWidget *parent = nullptr)
KUrlRequester(QWidget *editWidget, QWidget *parent)
KUrlRequester(const QUrl &url, QWidget *parent = nullptr)
(since 5.33) QFileDialog::AcceptMode acceptMode() const
QPushButton *button() const
KComboBox *comboBox() const
KUrlCompletion *completionObject() const
const KEditListWidget::CustomEditor &customEditor()
Qt::WindowModality fileDialogModality() const
KLineEdit *lineEdit() const
(since 5.31) QStringList mimeTypeFilters() const
KFile::Modes mode() const
(since 5.108) QStringList nameFilters() const
(since 5.0) QString placeholderText() const
(since 5.33) void setAcceptMode(QFileDialog::AcceptMode m)
void setFileDialogModality(Qt::WindowModality modality)
(since 5.31) void setMimeTypeFilters(const QStringList &mimeTypes)
void setMode(KFile::Modes mode)
(since 5.108) void setNameFilter(const QString &filter)
(since 5.108) void setNameFilters(const QStringList &filters)
(since 5.0) void setPlaceholderText(const QString &msg)
QUrl startDir() const
QString text() const
QUrl url() const

Public Slots

void clear()
void setStartDir(const QUrl &startDir)
void setText(const QString &text)
void setUrl(const QUrl &url)

Signals

void openFileDialog(KUrlRequester *)
void returnPressed(const QString &text)
void textChanged(const QString &)
(since 5.21) void textEdited(const QString &)
void urlSelected(const QUrl &)

Detailed Description

This class is a widget showing a lineedit and a button, which invokes a filedialog. File name completion is available in the lineedit.

The default for the filedialog is to ask for one existing local file, i.e. the default mode is 'KFile::File | KFile::ExistingOnly | KFile::LocalOnly', which you can change by using setMode().

The default filter is "*", i.e. show all files, which you can change by using setNameFilters() or setMimeTypeFilters().

By default the start directory is the current working directory, or the last directory where a file has been selected previously, you can change this behavior by calling setStartDir().

The default window modality for the file dialog is Qt::ApplicationModal

TODO qdoc

[Missing image html]

Property Documentation

acceptMode : QFileDialog::AcceptMode

Access functions:

QFileDialog::AcceptMode acceptMode() const
void setAcceptMode(QFileDialog::AcceptMode m)

fileDialogModality : Qt::WindowModality

Access functions:

Qt::WindowModality fileDialogModality() const
void setFileDialogModality(Qt::WindowModality modality)

mode : KFile::Modes

Access functions:

KFile::Modes mode() const
void setMode(KFile::Modes mode)

[since 5.108] nameFilters : QStringList

This property was introduced in 5.108.

Access functions:

QStringList nameFilters() const
void setNameFilters(const QStringList &filters)

placeholderText : QString

Access functions:

QString placeholderText() const
void setPlaceholderText(const QString &msg)

text : QString

Access functions:

QString text() const
void setText(const QString &text)

Notifier signal:

void textChanged(const QString &)

url : QUrl

Access functions:

QUrl url() const
void setUrl(const QUrl &url)

Notifier signal:

void textChanged(const QString &)

Member Function Documentation

[explicit] KUrlRequester::KUrlRequester(QWidget *parent = nullptr)

Constructs a KUrlRequester widget.

KUrlRequester::KUrlRequester(QWidget *editWidget, QWidget *parent)

Special constructor, which creates a KUrlRequester widget with a custom edit-widget. The edit-widget can be either a KComboBox or a KLineEdit (or inherited thereof). Note: for geometry management reasons, the edit-widget is reparented to have the KUrlRequester as parent.

[explicit] KUrlRequester::KUrlRequester(const QUrl &url, QWidget *parent = nullptr)

Constructs a KUrlRequester widget with the initial URL url.

[since 5.33] QFileDialog::AcceptMode KUrlRequester::acceptMode() const

Returns the current open / save mode

Note: Getter function for property acceptMode.

This function was introduced in 5.33.

See also setAcceptMode() and QFileDialog::acceptMode().

QPushButton *KUrlRequester::button() const

Returns a pointer to the pushbutton. It is provided so that you can specify an own pixmap or a text, if you really need to.

[slot] void KUrlRequester::clear()

Clears the lineedit/combobox.

KComboBox *KUrlRequester::comboBox() const

Returns a pointer to the combobox, in case you have set one using the special constructor. Returns 0L otherwise.

KUrlCompletion *KUrlRequester::completionObject() const

Returns the KUrlCompletion object used in the lineedit/combobox.

const KEditListWidget::CustomEditor &KUrlRequester::customEditor()

Returns an object, suitable for use with KEditListWidget. It allows you to put this KUrlRequester into a KEditListWidget. Basically, do it like this:

KUrlRequester *req = new KUrlRequester( someWidget );
[...]
KEditListWidget *editListWidget = new KEditListWidget( req->customEditor(), someWidget );

Qt::WindowModality KUrlRequester::fileDialogModality() const

Returns the window modality of the file dialog set with setFileDialogModality

Note: Getter function for property fileDialogModality.

See also setFileDialogModality().

KLineEdit *KUrlRequester::lineEdit() const

Returns a pointer to the lineedit, either the default one, or the special one, if you used the special constructor.

It is provided so that you can e.g. set an own completion object (e.g. KShellCompletion) into it.

[since 5.31] QStringList KUrlRequester::mimeTypeFilters() const

Returns the MIME type filters for the file dialog.

This function was introduced in 5.31.

See also setMimeTypeFilters() and QFileDialog::mimeTypeFilters().

KFile::Modes KUrlRequester::mode() const

Returns the current mode

Note: Getter function for property mode.

See also setMode() and QFileDialog::fileMode().

[since 5.108] QStringList KUrlRequester::nameFilters() const

Returns the filters for the file dialog.

Note: Getter function for property nameFilters.

This function was introduced in 5.108.

See also setNameFilters() and QFileDialog::nameFilters().

[signal] void KUrlRequester::openFileDialog(KUrlRequester *)

Emitted before the filedialog is going to open. Connect to this signal to "configure" the filedialog, e.g. set the filefilter, the mode, a preview-widget, etc. It's usually not necessary to set a URL for the filedialog, as it will get set properly from the editfield contents.

If you use multiple KUrlRequesters, you can connect all of them to the same slot and use the given KUrlRequester pointer to know which one is going to open.

[since 5.0] QString KUrlRequester::placeholderText() const

Returns the message set with setPlaceholderText

Note: Getter function for property placeholderText.

This function was introduced in 5.0.

See also setPlaceholderText().

[signal] void KUrlRequester::returnPressed(const QString &text)

Emitted when return or enter was pressed in the lineedit. The parameter contains the contents of the lineedit.

[since 5.33] void KUrlRequester::setAcceptMode(QFileDialog::AcceptMode m)

Sets the open / save mode of the file dialog.

The default is QFileDialog::AcceptOpen.

Note: Setter function for property acceptMode.

This function was introduced in 5.33.

See also acceptMode() and QFileDialog::setAcceptMode().

void KUrlRequester::setFileDialogModality(Qt::WindowModality modality)

Set the window modality for the file dialog to modality Directory selection dialogs are always modal

The default is Qt::ApplicationModal.

Note: Setter function for property fileDialogModality.

See also fileDialogModality().

[since 5.31] void KUrlRequester::setMimeTypeFilters(const QStringList &mimeTypes)

Sets the MIME type filters for the file dialog.

This function was introduced in 5.31.

See also mimeTypeFilters() and QFileDialog::setMimeTypeFilters().

void KUrlRequester::setMode(KFile::Modes mode)

Sets the mode of the file dialog.

The default mode of the file dialog is 'KFile::File | KFile::ExistingOnly | KFile::LocalOnly', which you can change using this method.

Note: You can only select one file from the file dialog invoked by KUrlRequester, hence setting KFile::Files doesn't make much sense here.

mode an OR'ed combination of KFile::Modes flags

Note: Setter function for property mode.

See also mode() and QFileDialog::setFileMode().

[since 5.108] void KUrlRequester::setNameFilter(const QString &filter)

Sets the filters for the file dialog.

This function was introduced in 5.108.

See also QFileDialog::setNameFilter().

[since 5.108] void KUrlRequester::setNameFilters(const QStringList &filters)

Sets the filters for the file dialog.

Note: Setter function for property nameFilters.

This function was introduced in 5.108.

See also nameFilters() and QFileDialog::setNameFilters().

[since 5.0] void KUrlRequester::setPlaceholderText(const QString &msg)

This makes the KUrlRequester line edit display a grayed-out hinting text as long as the user didn't enter any text. It is often used as indication about the purpose of the line edit.

Note: Setter function for property placeholderText.

This function was introduced in 5.0.

See also placeholderText().

[slot] void KUrlRequester::setStartDir(const QUrl &startDir)

Sets the start dir startDir.

The start dir is only used when the URL isn't set.

See also startDir().

[slot] void KUrlRequester::setText(const QString &text)

Sets the current text in the lineedit or combobox.

This is used for cases where KUrlRequester is used to enter URL-or-something-else, like KOpenWithDialog where you can type a full command with arguments.

Note: Setter function for property text.

See also text.

[slot] void KUrlRequester::setUrl(const QUrl &url)

Sets the url in the lineedit to url.

Note: Setter function for property url.

See also url().

QUrl KUrlRequester::startDir() const

Returns the current start dir

See also setStartDir().

QString KUrlRequester::text() const

Returns the current text in the lineedit or combobox. This does not do the URL expansion that url() does, it's only provided for cases where KUrlRequester is used to enter URL-or-something-else, like KOpenWithDialog where you can type a full command with arguments.

Note: Getter function for property text.

See also setText().

[signal] void KUrlRequester::textChanged(const QString &)

Emitted when the text in the lineedit changes. The parameter contains the contents of the lineedit.

Note: Notifier signal for property text. Notifier signal for property url.

[signal, since 5.21] void KUrlRequester::textEdited(const QString &)

Emitted when the text in the lineedit was modified by the user. Unlike textChanged(), this signal is not emitted when the text is changed programmatically, for example, by calling setText().

This function was introduced in 5.21.

QUrl KUrlRequester::url() const

Returns the current url in the lineedit. May be malformed, if the user entered something weird. For local files, ~user or environment variables are substituted, relative paths will be resolved against startDir()

Note: Getter function for property url.

See also setUrl().

[signal] void KUrlRequester::urlSelected(const QUrl &)

Emitted when the user changed the URL via the file dialog. The parameter contains the contents of the lineedit.