KUrlRequester Class
Header: | #include <KUrlRequester> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS KIOWidgets) target_link_libraries(mytarget PRIVATE Qt6::KIOWidgets) |
Public Functions
KUrlRequester(QWidget *parent = nullptr) | |
KUrlRequester(QWidget *editWidget, QWidget *parent) | |
KUrlRequester(const QUrl &url, QWidget *parent = nullptr) | |
virtual | ~KUrlRequester() override |
QFileDialog::AcceptMode | acceptMode() const |
QPushButton * | button() const |
KComboBox * | comboBox() const |
KUrlCompletion * | completionObject() const |
const KEditListWidget::CustomEditor & | customEditor() |
virtual QFileDialog * | fileDialog() const |
Qt::WindowModality | fileDialogModality() const |
KLineEdit * | lineEdit() const |
QStringList | mimeTypeFilters() const |
KFile::Modes | mode() const |
QStringList | nameFilters() const |
QString | placeholderText() const |
void | setAcceptMode(QFileDialog::AcceptMode m) |
void | setFileDialogModality(Qt::WindowModality modality) |
void | setMimeTypeFilters(const QStringList &mimeTypes) |
void | setMode(KFile::Modes mode) |
void | setNameFilter(const QString &filter) |
void | setNameFilters(const QStringList &filters) |
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 &) |
void | textEdited(const QString &) |
void | urlSelected(const QUrl &) |
Detailed Description
@class KUrlRequester kurlrequester.h <KUrlRequester>
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
[Missing image html]
@short A widget to request a filename/url from the user @author Carsten Pfeiffer <pfeiffer@kde.org>
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 @p url.
[override virtual noexcept]
KUrlRequester::~KUrlRequester()
Destructs the KUrlRequester.
QFileDialog::AcceptMode KUrlRequester::acceptMode() const
Returns the current open / save mode @see QFileDialog::acceptMode() @since 5.33
Note: Getter function for property acceptMode.
See also setAcceptMode().
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 );
[virtual]
QFileDialog *KUrlRequester::fileDialog() const
@returns a pointer to the filedialog. You can use this to customize the dialog, e.g. to call setLocationLabel or other things which are not accessible in the KUrlRequester API.
Never returns 0. This method creates the file dialog on demand.
@deprecated since 5.0. The dialog will be created anyway when the user requests it, and will behave according to the properties of KUrlRequester.
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.
QStringList KUrlRequester::mimeTypeFilters() const
Returns the MIME type filters for the file dialog. @see QFileDialog::mimeTypeFilters() @since 5.31
See also setMimeTypeFilters().
KFile::Modes KUrlRequester::mode() const
Returns the current mode @see QFileDialog::fileMode()
Note: Getter function for property mode.
See also setMode().
QStringList KUrlRequester::nameFilters() const
Returns the filters for the file dialog. @see QFileDialog::nameFilters() @since 5.108
Note: Getter function for property nameFilters.
See also setNameFilters().
[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.
QString KUrlRequester::placeholderText() const
@return the message set with setPlaceholderText @since 5.0
Note: Getter function for property placeholderText.
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.
void KUrlRequester::setAcceptMode(QFileDialog::AcceptMode m)
Sets the open / save mode of the file dialog.
The default is QFileDialog::AcceptOpen.
@see QFileDialog::setAcceptMode() @since 5.33
Note: Setter function for property acceptMode.
See also acceptMode().
void KUrlRequester::setFileDialogModality(Qt::WindowModality modality)
Set the window modality for the file dialog to @p modality Directory selection dialogs are always modal
The default is Qt::ApplicationModal.
Note: Setter function for property fileDialogModality.
See also fileDialogModality().
void KUrlRequester::setMimeTypeFilters(const QStringList &mimeTypes)
Sets the MIME type filters for the file dialog. @see QFileDialog::setMimeTypeFilters() @since 5.31
See also mimeTypeFilters().
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.
@param mode an OR'ed combination of KFile::Modes flags
@see QFileDialog::setFileMode()
Note: Setter function for property mode.
See also mode().
void KUrlRequester::setNameFilter(const QString &filter)
Sets the filters for the file dialog. @see QFileDialog::setNameFilter() @since 5.108
void KUrlRequester::setNameFilters(const QStringList &filters)
Sets the filters for the file dialog. @see QFileDialog::setNameFilters() @since 5.108
Note: Setter function for property nameFilters.
See also nameFilters().
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. @since 5.0
Note: Setter function for property placeholderText.
See also placeholderText().
[slot]
void KUrlRequester::setStartDir(const QUrl &startDir)
Sets the start dir @p 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.
@see text
Note: Setter function for property text.
See also text().
[slot]
void KUrlRequester::setUrl(const QUrl &url)
Sets the url in the lineedit to @p 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.
[signal]
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(). @since 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.