I'm in the process of porting a program from Qt4 to Qt5. I got it to the point where it compiles with both versions. Almost everything seems to work in the new version, excepted that I have lost the Ctrl+U
keyboard shortcut in the Qt5 version in two different contexts:
- in a dialog box, using a
QShortcut
assigned to theCtrl+U
key sequence - in the main window, when listening for evens in an event filter.
This seems specific to Ctrl+U
. I know that in the dialog box, other shortcuts like Ctrl+F
or Ctrl+W
work as they used to, and that in the main window, Ctrl+P
works as before too.
Is there anything special about Ctrl+U
(and possibly others) in Qt5 that prevent me from seeing the event ?
Edit
It seems it is linked to the presence of a line edit. MWE:
#include "mw.hh"
#include <QApplication>
#include <QShortcut>
#include <QStatusBar>
#include <QKeySequence>
#include <QTextStream>
#include <QLineEdit>
static void registerShortCut(const QKeySequence & seq, QWidget * receiver,
const char * fn,
Qt::ShortcutContext context = Qt::WindowShortcut)
{
QShortcut * sc = new QShortcut(seq, receiver);
sc->setContext(context);
receiver->connect(sc, SIGNAL(activated()), fn);
}
MW::MW()
{
statusBar()->showMessage("stuff");
registerShortCut(QKeySequence(tr("Ctrl+T")),
this, SLOT(test()));
registerShortCut(QKeySequence(tr("Ctrl+U")),
this, SLOT(test2()));
QLineEdit * le = new QLineEdit("stuff");
setCentralWidget(le);
}
void MW::test()
{
statusBar()->showMessage("Test !");
}
void MW::test2()
{
statusBar()->showMessage("Test 2 !");
}
int main(int argc, char ** argv)
{
QApplication main(argc, argv);
MW mw;
mw.show();
main.exec();
}
With mw.hh
:
#include <QMainWindow>
class MW : public QMainWindow {
Q_OBJECT;
public:
MW();
public slots:
void test();
void test2();
};
Hitting Ctrl+T
shows Test in the status bar, but Ctrl+U
does not. Commenting out the setCentralWidget(le)
line restores the expected behaviour.