{"id":300,"date":"2017-03-07T21:39:09","date_gmt":"2017-03-07T20:39:09","guid":{"rendered":"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=300"},"modified":"2017-03-07T22:39:58","modified_gmt":"2017-03-07T21:39:58","slug":"kglobalaccel","status":"publish","type":"post","link":"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=300","title":{"rendered":"KGlobalAccel"},"content":{"rendered":"<p>This definitely merits a post. While working on my Qt Audio Player (<a href=\"https:\/\/tollana.d-tor.org\/cgit\/BeetPlayer\/\" target=\"_blank\">BeetPlayer<\/a>), I wanted control it via the Media Keys of my Keyboard. Since I&#8217;m using KDE on Linux, I quickly found out about KGlobalAccel.<\/p>\n<p>Unfortunately, there&#8217;s no decent documentation available. The\u00a0<a href=\"https:\/\/api.kde.org\/frameworks\/kglobalaccel\/html\/classKGlobalAccel.html\" target=\"_blank\">API docs<\/a>\u00a0are kinda useless, and there&#8217;s no tutorial available, at least not with my Google foo, so here is how it works:<\/p>\n<p>First and foremost, set QObject::objectName() for the QAction you want to register. It should be unique!<\/p>\n<p>Don&#8217;t forget to change your CMake file or your .pro-File if you&#8217;re using qmake.<\/p>\n<p>Then register a shortcut with\u00a0KGlobalAccel::self()-&gt;setShortcut() like this:<\/p>\n<pre>QAction *muteA = new QAction(QIcon(\":\/mute.png\"), tr(\"Mute\"), this); \r\nmuteA-&gt;setObjectName(\"beetPlayerMute\"); \r\nconnect(muteA, SIGNAL(triggered(bool)), this, SLOT(mute(bool))); \r\nKGlobalAccel::self()-&gt;setShortcut(muteA, QList&lt;QKeySequence&gt;() &lt;&lt; QKeySequence(Qt::Key_VolumeMute), KGlobalAccel\r\n::Autoloading);<\/pre>\n<p>After that launch KDE System Settings-&gt;Shortcuts-&gt;Global Shortcuts. There should be an entry for your Application. Select it and set the shortcut. Haven&#8217;t figured out how a default shortcut, but it doesn&#8217;t really matter when it shows up there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This definitely merits a post. While working on my Qt Audio Player (BeetPlayer), I wanted control it via the Media Keys of my Keyboard. Since I&#8217;m using KDE on Linux, I quickly found out about KGlobalAccel. Unfortunately, there&#8217;s no decent documentation available. The\u00a0API docs\u00a0are kinda useless, and there&#8217;s no tutorial available, at least not with &hellip; <a href=\"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=300\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">KGlobalAccel<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[15,96],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-desktop","tag-kde","tag-programming"],"_links":{"self":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=300"}],"version-history":[{"count":4,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":304,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/300\/revisions\/304"}],"wp:attachment":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}