Bolick
15th July 2009, 15:17
I made a basic QT application which has say 4 QPushButtons and 2 QCheckBoxes.
I want to implement such behavior:
1-st push button acts like "Tab"
2-nd button acts like "Tab+Shift"
3-rd button acts like "Space"
4-th button as "Enter"
All buttons are set with focusPolicy=NoFocus
So only checkboxes could be selected with focus.
This way I want to select one of the checkboxes (pressing 1-st and 2-nd buttons) then open its pop-up with 3-rd and select option by 4-th.
Actions for buttons are like that:
void my_app::on_pb_control_0_clicked ()
{
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "Tab", false, 0 );
QApplication::sendEvent(this, &key);
}
void my_app::on_pb_control_1_clicked ()
{
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "Tab-Shift", false, 0 );
QApplication::sendEvent(this, &key);
}
void my_app::on_pb_control_2_clicked ()
{
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "Return", false, 0 );
QApplication::sendEvent(this, &key);
}
void my_app::on_pb_control_3_clicked ()
{
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Space, Qt::NoModifier, "Space", false, 0 );
QApplication::sendEvent(this, &key);
}
As a result I have the desired behavior only for "Tab" and "Tab-Shift" pushbuttons (pb_control_0 and _1).
And nothing happens while I press pb_control_2 and _3.
But if I press "Enter" or "Space" on the real keyboard Checkbox widget acts in the right way (on Space popup opens and on Enter one of the options selects and popup closes).
So, what is wrong in my actions?
I want to implement such behavior:
1-st push button acts like "Tab"
2-nd button acts like "Tab+Shift"
3-rd button acts like "Space"
4-th button as "Enter"
All buttons are set with focusPolicy=NoFocus
So only checkboxes could be selected with focus.
This way I want to select one of the checkboxes (pressing 1-st and 2-nd buttons) then open its pop-up with 3-rd and select option by 4-th.
Actions for buttons are like that:
void my_app::on_pb_control_0_clicked ()
{
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "Tab", false, 0 );
QApplication::sendEvent(this, &key);
}
void my_app::on_pb_control_1_clicked ()
{
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "Tab-Shift", false, 0 );
QApplication::sendEvent(this, &key);
}
void my_app::on_pb_control_2_clicked ()
{
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "Return", false, 0 );
QApplication::sendEvent(this, &key);
}
void my_app::on_pb_control_3_clicked ()
{
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Space, Qt::NoModifier, "Space", false, 0 );
QApplication::sendEvent(this, &key);
}
As a result I have the desired behavior only for "Tab" and "Tab-Shift" pushbuttons (pb_control_0 and _1).
And nothing happens while I press pb_control_2 and _3.
But if I press "Enter" or "Space" on the real keyboard Checkbox widget acts in the right way (on Space popup opens and on Enter one of the options selects and popup closes).
So, what is wrong in my actions?