|
|
Hi,
Just noticed an odd behavior with menu shortcuts and
the QSpinBox widget (FreeBSD 5.4, Qt 4.0.1). Even when
a spinbox has keyboard focus, menu shortcuts still
take precedence over typed keys; for example if you
have the keyboard shortcut "0" (zero) attached to a
menu item, there's no way to type a zero into a
spinbox, because the shortcut is always called
instead. This doesn't happen with QLineEdit widgets,
when they have keyboard focus they get first pick of
the keys.
Here's some example code where you can type zero into
a line edit but not a spin box:
#include <QKeySequence>
#include <QAction>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QSpinBox>
#include <QMenu>
#include <QMenuBar>
#include <QMainWindow>
#include <QApplication>
class Widget : public QWidget {
public:
Widget();
};
class Window : public QMainWindow {
public:
Window();
};
Widget::Widget()
{
QLineEdit * lineEdit = new QLineEdit;
QSpinBox * spinBox = new QSpinBox;
QVBoxLayout * layout = new QVBoxLayout;
layout->addWidget(lineEdit);
layout->addWidget(spinBox);
setLayout(layout);
}
Window::Window()
{
QAction * action = new QAction(this);
QMenu * menu = menuBar()->addMenu("menu");
Widget * widget = new Widget;
action->setShortcut(QKeySequence("0"));
menu->addAction(action);
setCentralWidget(widget);
}
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
|
|