Reputation:
There's a cool guitar tabbing application that I've used before where you can use the keyboard to move around a character grid. You can put any digit in any character cell. Here is an image:
In effect, it works just like the Linux console where you have a cursor block and you can move around character by character.
I am using Qt as my GUI application. How would I go about adding this type of single-character editor control in my application? I have not run across this type of widget in any of my exposure to GUI programming; hence, I'm not even sure what to call it or how to describe it succinctly.
Thanks.
Upvotes: 2
Views: 178
Reputation: 2239
First of all, you would have to implement handlers for each key you would like to respond to when pressed/release/hold.
The widget implementation would be like implementing a Finite State Machine with states like Navigating
and Editing
and so on.
For each key pressed you would act accordingly to update your widget or perform another action, including change the state of the widget.
In a high level form, this would be like:
void MyCrazyWidget::on_keyDown(QKeyEvent event) {
switch ( this->state() ) {
case State::Navigating:
this->navigatingStateHandleKeyDown(event);
break;
case State::Editing:
this->editingStateHandleKeyDown(event);
break;
default:
// waaaat???
}
}
void MyCrazyWidget::navigatingStateHandleKeyDown(QKeyEvent event) {
switch ( event.key() ) {
// handle each of the keys here (or simply ignore those without an action).
}
}
void MyCrazyWidget::editingStateHandleKeyDown(QKeyEvent event) {
switch ( event.key() ) {
// handle each of the keys here (or simply ignore those without an action).
}
}
This is obviously very high level, but is pretty much these things are handled (afaik). It's a boring and hard job, but we really need our editors ;D
Upvotes: 1