KShortcutsDialog Class
Dialog for configuration of KActionCollection and KGlobalAccel. More...
Header: | #include <KShortcutsDialog> |
CMake: | find_package(KF6 REQUIRED COMPONENTS XmlGui) target_link_libraries(mytarget PRIVATE KF6::XmlGui) |
Inherits: | QDialog |
Public Functions
(since 5.85) | KShortcutsDialog(QWidget *parent) |
KShortcutsDialog(KShortcutsEditor::ActionTypes actionTypes = KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcuts allowLetterShortcuts = KShortcutsEditor::LetterShortcutsAllowed, QWidget *parent = nullptr) | |
virtual | ~KShortcutsDialog() override |
QList<KActionCollection *> | actionCollections() const |
(since 5.97) void | addActionToSchemesMoreButton(QAction *action) |
void | addCollection(KActionCollection *collection, const QString &title = {}) |
bool | configure(bool saveSettings = true) |
(since 5.15) void | exportConfiguration(const QString &path) const |
(since 5.15) void | importConfiguration(const QString &path) |
(since 5.97) void | refreshSchemes() |
Reimplemented Public Functions
virtual QSize | sizeHint() const override |
Public Slots
virtual void | accept() override |
Signals
void | saved() |
Static Public Members
(since 5.84) void | showDialog(KActionCollection *collection, KShortcutsEditor::LetterShortcuts allowLetterShortcuts = KShortcutsEditor::LetterShortcutsAllowed, QWidget *parent = nullptr) |
Detailed Description
This dialog can be used to configure keyboard shortcuts associated with actions in KActionCollection and KGlobalAccel. It integrates the KShortcutsEditor widget and offers various functionalities related to keyboard shortcuts (e.g. reset all shortcuts to defaults, manage shortcuts schemes ...etc).
Several static methods are supplied, which provide a convenient interface to the dialog. The most common, and most encouraged, use is with a KActionCollection.
KShortcutsDialog::configure(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed, parent); // Alternatively, since 5.84, you can use: KShortcutsDialog::showDialog(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed, parent);
By default this dialog is modal (since 4.3). If you don't want that, call setModal(false)
and then the non-static configure() method to show the dialog.
If you need to run some extra code when the dialog is closed, connect to the signals emitted by QDialog
(accepted(), rejected(), finished() ...etc.). However, note that if that extra code depends on the changed settings having already been saved, connect to the saved()
signal instead to be on the safe side (if you connect to e.g. QDialog::accepted()
your function might be called before the changes have actually been saved).
Note: Starting from 5.95, if there are no Global shortcuts in any of the action collections shown in the dialog, the relevant columns ("Global" and "Global Alternate") will be hidden.
Example:
// Create the dialog; alternatively you can use the other constructor if e.g. // you need to only show certain action types, or disallow single letter shortcuts KShortcutsDialog *dlg = new KShortcutsDialog(parent); // Set the Qt::WA_DeleteOnClose attribute, so that the dialog is automatically // deleted after it's closed dlg->setAttribute(Qt::WA_DeleteOnClose); // Add an action collection (otherwise the dialog would be empty) dlg->addCollection(actionCollection()); // Run some extra code after the settings are saved connect(dlg, &KShortcutsDialog::saved, this, &ClassFoo::doExtraStuff); // Called with "true" so that the changes are saved if the dialog is accepted, // see the configure(bool) method for more details dlg->configure(true);
Member Function Documentation
[explicit, since 5.85]
KShortcutsDialog::KShortcutsDialog(QWidget *parent)
Constructs a KShortcutsDialog as a child of parent, with the default settings.
The default settings are KShortcutsEditor::AllActions and KShortcutsEditor::LetterShortcutsAllowed.
Typically a KActionCollection is added by using addCollection().
parent The parent widget of the dialog. If not, nullptr
will be used by the window manager to place the dialog relative to it.
This function was introduced in 5.85.
[explicit]
KShortcutsDialog::KShortcutsDialog(KShortcutsEditor::ActionTypes actionTypes = KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcuts allowLetterShortcuts = KShortcutsEditor::LetterShortcutsAllowed, QWidget *parent = nullptr)
Constructs a KShortcutsDialog as a child of parent.
actionTypes Sets the action types to be shown in the dialog. This is an OR combination of KShortcutsEditor::ActionTypes
; the default is KShortcutsEditor::AllActions
.
allowLetterShortcuts Set to false if unmodified alphanumeric keys ('A', '1', etc.) are not permissible shortcuts.
parent parent widget of the dialog, if not set nullptr
will be used by the window manager to place the dialog relative to it.
See also KShortcutsEditor::LetterShortcuts.
[override virtual noexcept]
KShortcutsDialog::~KShortcutsDialog()
Destructor.
Deletes all resources used by a KShortcutsDialog object.
[override virtual slot]
void KShortcutsDialog::accept()
Reimplements: QDialog::accept().
QList<KActionCollection *> KShortcutsDialog::actionCollections() const
Returns the list of action collections that are available for configuration in the dialog.
[since 5.97]
void KShortcutsDialog::addActionToSchemesMoreButton(QAction *action)
Adds an action to the "More Actions" menu.
This is useful to add for example an action to download more keyboard schemes via KNewStuff.
This function was introduced in 5.97.
void KShortcutsDialog::addCollection(KActionCollection *collection, const QString &title = {})
Adds all actions of the collection to the ones displayed and configured by the dialog.
title The title associated with the collection. If null, the KAboutData::progName() of the collection's componentData is used).
bool KShortcutsDialog::configure(bool saveSettings = true)
Runs the dialog and call writeSettings() on the action collections that were added if saveSettings is true.
If the dialog is modal this method will use QDialog::exec()
to open the dialog, otherwise it will use QDialog::show()
.
[since 5.15]
void KShortcutsDialog::exportConfiguration(const QString &path) const
Exports a shortcut set up from path.
This function was introduced in 5.15.
[since 5.15]
void KShortcutsDialog::importConfiguration(const QString &path)
Imports a shortcut set up from path.
This function was introduced in 5.15.
[since 5.97]
void KShortcutsDialog::refreshSchemes()
Reloads the list of schemes in the "Manage Schemes" section.
This is useful if the available scheme files changed for some reason (for example, because KNewStuff was used).
This function was introduced in 5.97.
[signal]
void KShortcutsDialog::saved()
Emitted after the dialog is accepted (by clicking the OK button) and settings are saved.
Connect to this signal if you need to run some extra code after the settings are saved.
[static, since 5.84]
void KShortcutsDialog::showDialog(KActionCollection *collection, KShortcutsEditor::LetterShortcuts allowLetterShortcuts = KShortcutsEditor::LetterShortcutsAllowed, QWidget *parent = nullptr)
This static method shows a modal dialog that can be used to configure the shortcuts associated with each action in collection.
The new shortcut settings will be saved and applied if the dialog is accepted.
The dialog is opened by using QDialog::show()
, and it will be deleted automatically when it's closed.
Example usage:
// Typical usage is with a KActionCollection: KShortcutsDialog::showDialog(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed, parent);
collection The KActionCollection to configure.
allowLetterShortcuts Set to KShortcutsEditor::LetterShortcutsDisallowed
if unmodified alphanumeric keys ('A', '1', etc.) are not permissible shortcuts.
parent The parent widget of the dialog, if not set nullptr
will be used by the window manager to place the dialog relative to it.
This function was introduced in 5.84.
[override virtual]
QSize KShortcutsDialog::sizeHint() const
Reimplements: QDialog::sizeHint() const.
See also QWidget::sizeHint().