[Interest] QPushButton shortcut works on Qt 4 but not 5

Elvis Stansvik elvstone at gmail.com
Sat May 7 15:44:39 CEST 2016


2016-05-07 15:27 GMT+02:00 Elvis Stansvik <elvstone at gmail.com>:
> Hi all,
>
> Maybe I'm doing something completely wrong, but on Qt 4.8.7, this
> works (pressing Ctrl+O prints "clicked"):
>
> test.cpp:
>
> #include <QApplication>
> #include <QMainWindow>
> #include <QPushButton>
> #include <QWidget>
> #include <QDebug>
>
> class MainWindow : public QMainWindow {
>     Q_OBJECT
>
> public:
>     MainWindow(QWidget *parent = 0) : QMainWindow(parent) {
>         QPushButton *button = new QPushButton("Click Me (Ctrl+O)");
>         button->setShortcut(QString("Ctrl+O"));
>         connect(button, SIGNAL(clicked()), this, SLOT(onClicked()));
>
>         setCentralWidget(button);
>     }
>
> public slots:
>     void onClicked() {
>         qDebug() << "clicked";
>     }
> };
>
> int main(int argc, char *argv[]) {
>     QApplication app(argc, argv);
>
>     MainWindow window;
>     window.show();
>
>     return app.exec();
> }
>
> #include "moc_test.cpp"
>
> but on Qt 5.6.0 it does not (nothing printed on Ctrl+O).

I just tested on a couple of other machines (Qt 5.2.1 and Qt 5.5.1),
and it worked on both of them. So something broke in Qt 5.6.0? Or Arch
somehow broke my Qt?

If anyone else is under KDE on Arch and could give it a try, I would
much appreciate it.

Elvis

>
> test.pro for building:
>
> TEMPLATE = app
> greaterThan(QT_MAJOR_VERSION, 4):QT += widgets
> TARGET = test
> INCLUDEPATH += .
>
> # Input
> SOURCES += test.cpp
> HEADERS += test.cpp
>
> Any ideas what may be going wrong? My window manager (KWin) is not
> intercepting Ctrl+O (obviously). And besides, it doesn't seem to
> matter which shortcut I use.
>
> Thanks in advance,
> Elvis



More information about the Interest mailing list