<div dir="ltr"><div>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.</div><div><br></div><div>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.</div><div><br></div><div>#include <QApplication> <br>#include <QKeyEvent> <br>#include <QKeySequenceEdit> <br>#include <QVBoxLayout> <br> <br>#include <iostream> <br> <br>class MyWidget : public QWidget <br>{ <br> public: <br> MyWidget() = default; <br> ~MyWidget() = default; <br> <br> bool event(QEvent *e) override { <br> if (e->type() == QEvent::KeyPress) { <br> QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e); <br> std::cout << "TEST WIDGET EVENT KEY: " << ke->key() << std::endl; <br> } <br> return QWidget::event(e); <br> } <br>}; <br> <br>class MyLayout : public QVBoxLayout <br>{ <br> public: <br> MyLayout() = default; <br> ~MyLayout() = default; <br> <br> bool event(QEvent *e) override { <br> if (e->type() == QEvent::KeyPress) { <br> QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e); <br> std::cout << "TEST LAYOUT EVENT KEY: " << ke->key() << std::endl; <br> } <br> return QLayout::event(e); <br> } <br>}; <br> <br>class MyApplication : public QApplication <br>{ <br> public: <br> MyApplication(int &argc, char **argv) : QApplication(argc, argv) {} <br> ~MyApplication() = default; <br> <br> bool event(QEvent *e) override { <br> if (e->type() == QEvent::KeyPress) { <br> QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e); <br> std::cout << "TEST APPLICATION EVENT KEY: " << ke->key() << std::endl; <br> } <br> return QApplication::event(e); <br> } <br>};<br></div><div><br></div><div>class MyKeySequenceEdit : public QKeySequenceEdit <br>{ <br> public: <br> MyKeySequenceEdit() = default; <br> ~MyKeySequenceEdit() = default; <br> <br> bool event(QEvent *e) override { <br> if (e->type() == QEvent::KeyPress) { <br> QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e); <br> std::cout << "TEST KEY SEQUENCE EDIT EVENT KEY: " << ke->key() << std::endl;<br> } <br> return QKeySequenceEdit::event(e); <br> } <br> <br> void keyPressEvent(QKeyEvent *e) override { <br> std::cout << "TEST KEY SEQUENCE EDIT KEY PRESS EVENT KEY: " << e->key() << std::endl;<br> QKeySequenceEdit::keyPressEvent(e); <br> } <br>}; <br> <br>int main(int argc, char *argv[]) <br>{ <br> MyApplication app(argc, argv); <br> MyWidget mainWindow; <br> <br> QVBoxLayout* layout = new MyLayout; <br> <br> // If I comment the first out, I can assign tab to keySequenceEdit2 <br> QKeySequenceEdit* keySequenceEdit = new MyKeySequenceEdit(); <br> layout->addWidget(keySequenceEdit); <br> <br> QKeySequenceEdit* keySequenceEdit2 = new MyKeySequenceEdit(); <br> layout->addWidget(keySequenceEdit2); <br> <br> mainWindow.setLayout(layout); <br> mainWindow.show(); <br> return app.exec(); <br>}<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
</blockquote></div></div>