Is there an "easy" way to add customizable keyboard shortcuts to my Qt4 app? - qt

I've got a sizable Qt app that has been in development since the Qt 3 days, and it now contains dozens of windows with thousands of menu items, controls, and other user-initiatable actions. It currently compiles under Qt 4.6, for Linux, MacOS/X, and Windows.
The new feature request from on high is that the user should be able to customize any and all keyboard shortcuts in this app... i.e. there should be a "Customize Key Bindings..." menu item, that when chosen, opens up a dialog that lists all of the actions in the application and their current key binding (if any) and allows the user to assign or change key bindings for any and all actions he cares to, and then save his settings and use the applications with his own customized key bindings.
This seems like a rather ambitious thing to implement, considering the number of keyboard-able actions in the app, and I'm wondering if there is any existing classes or code libraries available to assist in this sort of thing, or if it's something I'm going to have to implement from scratch myself. The Qt internationalization system, in particular, seems like it might be adapted to help with something like this -- the difference being that instead of (actually in addition to) the developer choosing key combinations before shipping the app, the users could choose/alter key combinations while using the app (if they aren't happy with the shipped defaults, of course).
Does anyone have any hints or pointers on code or approaches towards implementing this feature?

I agree with JimDaniel, it sounds like the most generic approach would be to create a QAction for everything that you would to be executed through a Keyboard shortcut. The user then configures the appropriate shortcut for each action.
This is definitely a cleaner way to implement this than overriding the events, it also then lets you put your actions into menus and toolbars, I don't know how much work this would be for your application.

You could store the bindings in an application config file and read it in upon app startup. Then whenever the user changes bindings update this file. Keys are just enums in the Qt framework. You can override the appropriate keyPressEvent() or keyReleaseEvent(), check the key(s) pressed and match against the current bindings.

Here is what I found before this thread :
http://doc.qt.nokia.com/qq/qq14-actioneditor.html
It's in Qt3 but I guess it's possible to write it in Qt4

Related

Is there a way to generate windows and/or components in Ignition?

I was hoping that Ignition had a way to import/export windows to a non-binary format such as JSON or XML, but that seems not to be the case (or is there a way?).
Is there a way to use the script console to generate and populate a new window, or to insert components into an existing window?
This would be used for inserting templates and other components, such as navigation buttons etc.
Yes, but...
I assume here that you're referring to Vision windows. The windows are indeed binary serialized, but the underlying structure is XML. But getting the deserialization done programmatically is a pain and probably not worth it.
You can get a feel for what this looks like by opening a Vision window in the designer, right-clicking its Root Container and choosing Copy, then pasting it into Notepad. I myself tried to find a way to do this from a module and decided it wasn't worth it. For more detail, you can view that thread in the Ignition forum here.
However, that's not really useful for generating and populating a new window.
To do that, you need to do some Java programming. Vision is Java Swing under the hood. There are a couple ways you can dynamically build / populate a Window.
From Python, you can import any Java libraries you need and generate the window dynamically. For relatively simple things, you're probably better off working with the Template Canvas component. There's an Ignition forum thread discussing this topic here. This would be more of a run-time generation, not from the Script Console.
You can write your own module to do it.
Module SDK Vision Component Guide
Vision Component Module Example
Good luck!

is There any way to control programs by finding from task manager and managing contents?

Hello guess my title is bad enough to explain question but I am trying to understand is there any way to control and automate things just finding tasks from task manager? I have seen in Visual Studio "Spy++". Firstly, i didn't understand what it's aim and how far we can go with it. I just got it, it can provide us logs in a cool range.
I would like to give an example,
I want to log in Facebook/Twitter and do casual things with developed software by myself(I don't want to use selenium or any kind of that thing) or I want to get informations from a game which is about characters actual health, attack power, ability power... or giving command that game from my software like, press a,b or 1.
Can someone tell me, exact subject name of what i am talking about?
Terminology: Selenium / AutoIt: "UI automation". Reading and modifying in-game values: "memory editor" or "trainer".
There is no universal way to control programs if you want your tool to be transparent. A browser may listen to OS input events (Windows messages telling it which keys were pressed or where the mouse was clicked), games may use DirectInput and yet other apps may subscribe to low-level system events or hooks.
For example browser automation:
Using plugins/extensions gives you a JavaScript API that allows you to inspect pages, forms on those pages, modify browser behavior and whatnot.
Browsers can also have their own external API. This can be done by linking to their DLLs, or passing command line arguments, or passing messages in other ways. For Firefox, this API is named "Marionette".
Then there's Selenium, that provides a common API for various browsers. It controls them using "drivers".
Selenium "knows" how to drive a browser, as it's coded against the browser's APIs. Spy++ "knows" that it's inspecting a Win32 window and looks for known controls, their classes and their names so you could write another program to send specific messages to those specific controls of those specific applications.
As for "log in to Facebook", no, you cannot do that in a reasonable amount of time for the currently popular browsers if you want to code it from the ground on up.
You'll have to, in one way or the other, interface with the browser and ask for a handle to the username/password textboxes, enter data into them and then submit the form. Then you'll practically be rebuilding Selenium, so why not use that tool in the first place?
Or you'll have to scrape the pixels on the screen, recognize those textboxes, click the mouse there and send some keys. And then Facebook redesigns their login form and you'll have to start over.
tl;dr: use the right tool for the job. If you want to automate a site's UI, then use Selenium.

Is there any plan to add Qxt features to Qt?

Qxt is an extension library for Qt providing a suite of cross-platform utility classes to add functionality not readily available in Qt. Qxt consists of several modules, each of which lives in a separate library. It has many nice features like:
QSlider with two buttons
Rotating & richtext buttons and labels
LineEdit with sample text
managing many screen settings
String SpinBox
Check ComboBox
Global Shortcut (hot keys)
Schedule View
Tooltip with arbitrary widget on it
RPC(connecting signals and slots through network)
XML-RPC
QxtSQLPackage (Sending SQL query result through network or to a file)
QxtSlotMapper (Map a signal to slots based on parameter value)
Qt comes with lots of new features in each release. I wonder why these useful and nice features are not included in new versions of Qt. Does anybody know if there is any plan to add these features to Qt in the future?
While I do totally understand not just sending Qxt code up stream, because it can be very kludgy, some of the things mentioned are a bit silly as to why they're not included already. The global shortcuts is the number one thing that comes to mind. Having sample text in a line edit would be another cool feature.
For a while now, in my spare time, I've been working on a note taking app, and I've specifically went with QT because of the ease of having it work cross platform compared to GTK or other GUI frameworks. One of the major concepts was having a global hotkey to make the application appear and disappear, but because QT doesn't do this on its own, I had to deal with Qxt for this one function, and it made it a giant mess to get going. I dealt with tons of bugs that prevented me from building versions for Windows. If I could, I'd gladly ditch Qxt in favor of something already baked in to QT.
Qxt grew out of a need for features that QT wouldn't include for one reason or another, and I frankly just don't understand why.

How to map controls to physical keyboard locations

I've been wanting to create a game engine, but I want to sort out some issues such as how to do controls. Is it possible to map controls to the physical locations on the keyboard as opposed to the individual keys themselves?
I would like to do this because I think that simply configuring to controls like "W" for up and "S" for down is a nuisance for anyone who isn't using qwerty and needs to reconfigure to the locations intended by the creators of a game, which would include Dvorak users like myself or anyone who just decides to change the system default.
I'll probably be using C++ with Boost, SFML and Qt if that matters.
Probably the best way to do it would to simply have the controls in a .ini or text file, and then the user can configure it from there. Or else, a menu in the game from which you can select a key. i.e. "Press the key for up" etc. In terms of physical layouts, there aren't really any standards.
Anyway, even those using qwerty keyboards way want to customise their keys e.g. roguelike keys.

Qt and UI Skinning

I wanted to consult with the sages here regarding Qt and skinning, get your opinion and chart a path for my development. My requirements are as follows:
My Qt/C++ application (cross platform with Mac, Windows and Linux versions) needs to have modular skins.
A skin is defined as a set of one or more elements: - Window background texture - Look/feel of UI controls such as edit boxes, drop down, radio buttons, buttons etc. - Look/feel of window "caption", resize grips etc.
Skins will be installed with the application installer, allowing the user to choose which one he/she wants to use. Users should be able to change skins on the fly.
Can I go the QML route? should this be custom and based on simple resources which are built into the application? Any design advice will be appreciated.
Thanks.
If I understood you correctly then stylesheet is the best way forward. You can create stylesheets similar to CSS and then pass them as command line option to your application or load on invocation to style your application at runtime. That way you can create multiple stylesheets each having a different look and feel and allow user to load them at will. Since its CSS it doesn't need any new learning and you can keep all your styling outside your source code.
Here are a list of resources that can get you up and running quickly:
http://blog.qt.io/blog/2007/11/27/theming-qt-for-fun-and-profit/
http://doc.qt.io/qt-5/stylesheet.html
I haven't played with QML yet, but you could also create a custom QStyle implementation that supports your resource format. Note that you'd lose style sheet support if you went this route.
Changing window captions is a little trickier if you want portability.
QML, if I understand correctly, doesn't really skin the widgets, it mainly deals with GUI layout etc etc.
QStyle is used to change the looks. It is a bit low-level though, and requires programming, so if you want to load different user-created skins (from an XML or so) it might be tricky to support extensive skinning. Chaining colors and a few items are easy enough though. (There might be someone else who've done something you could re-use.. not sure.)
For modifying widgets, use QStyle::polish(). You could use that to change the background picture (if it's a top-level window, or of a certain class). There are numerous repaint method to change almost every part of every widget.
Store/load the style using QSettings, by reading and setting the desired Style just after QApplication but before your main window is constructed.

Resources