[Development] QKeySequenceEdit: Unable to assign tab
Laszlo Papp
lpapp at kde.org
Fri Jun 24 18:38:39 CEST 2022
I debugged this a bit further. It looks like bool
QKeySequence::event(QEvent *e); is hit for the tab key, but then
QKeySequence::keyPressEvent(QKeyEvent *e); is not.
I also checked all other GUI elements in the above code with My* subclasses
and none of those get the tab key under their event handlers. It has been
becoming more and more clear to me that this is a bug. Because it does get
the event, it just does not utilise it properly. Any clue why
QKeySequence::event(QEvent *e); does not make it into
QKeySequence::keyPressEvent(QKeyEvent *e); like all other keys? If I call
keyPressEvent manually, it obviously works better, but not sure what the
right solution is.
#include <QApplication>
#include <QKeyEvent>
#include <QKeySequenceEdit>
#include <QVBoxLayout>
#include <iostream>
class MyWidget : public QWidget
{
public:
MyWidget() = default;
~MyWidget() = default;
bool event(QEvent *e) override {
if (e->type() == QEvent::KeyPress) {
QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e);
std::cout << "TEST WIDGET EVENT KEY: " << ke->key() << std::endl;
}
return QWidget::event(e);
}
};
class MyLayout : public QVBoxLayout
{
public:
MyLayout() = default;
~MyLayout() = default;
bool event(QEvent *e) override {
if (e->type() == QEvent::KeyPress) {
QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e);
std::cout << "TEST LAYOUT EVENT KEY: " << ke->key() << std::endl;
}
return QLayout::event(e);
}
};
class MyApplication : public QApplication
{
public:
MyApplication(int &argc, char **argv) : QApplication(argc, argv) {}
~MyApplication() = default;
bool event(QEvent *e) override {
if (e->type() == QEvent::KeyPress) {
QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e);
std::cout << "TEST APPLICATION EVENT KEY: " << ke->key() <<
std::endl;
}
return QApplication::event(e);
}
};
class MyKeySequenceEdit : public QKeySequenceEdit
{
public:
MyKeySequenceEdit() = default;
~MyKeySequenceEdit() = default;
bool event(QEvent *e) override {
if (e->type() == QEvent::KeyPress) {
QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e);
std::cout << "TEST KEY SEQUENCE EDIT EVENT KEY: " << ke->key() <<
std::endl;
}
return QKeySequenceEdit::event(e);
}
void keyPressEvent(QKeyEvent *e) override {
std::cout << "TEST KEY SEQUENCE EDIT KEY PRESS EVENT KEY: " <<
e->key() << std::endl;
QKeySequenceEdit::keyPressEvent(e);
}
};
int main(int argc, char *argv[])
{
MyApplication app(argc, argv);
MyWidget mainWindow;
QVBoxLayout* layout = new MyLayout;
// If I comment the first out, I can assign tab to keySequenceEdit2
QKeySequenceEdit* keySequenceEdit = new MyKeySequenceEdit();
layout->addWidget(keySequenceEdit);
QKeySequenceEdit* keySequenceEdit2 = new MyKeySequenceEdit();
layout->addWidget(keySequenceEdit2);
mainWindow.setLayout(layout);
mainWindow.show();
return app.exec();
}
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20220624/1ae2b3c2/attachment.htm>
More information about the Development
mailing list