Hi, I have an application that works with Qt4 and uses the colon (":") as a shortcut for a QAction. I was testing out how the application worked under Qt5 and have found out that this particular shortcut does not work anymore. This isn't an issue specific to my application but with Qt5 in general, as it can be shown with the minimally reproducing application that I attach at the end of the message.
I have checked the docs but haven't found anything that has changed to guarantee this difference. Any idea on what it may be ? Or should I report this as a bug ?
Thanks,
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
{
Q_OBJECT
public:
~MainWindow();
public slots:
void performTestAction();
private:
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void performTestAction();
private:
QAction *testAction;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include <QMainWindow>
#include <QAction>
#include <QMessageBox>
MainWindow
::MainWindow(QWidget *parent
){
testAction
= new QAction("Test action",
this);
// Neither of this work in Qt5 but do work in Qt4
//testAction->setShortcut(QKeySequence(Qt::Key_Colon));
connect(testAction, SIGNAL(triggered()), this, SLOT(performTestAction()));
addAction(testAction);
}
MainWindow::~MainWindow()
{ }
void MainWindow::performTestAction()
{
messageBox.setText("The action has been executed.");
messageBox.exec();
}
#include "mainwindow.h"
#include <QMainWindow>
#include <QAction>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
testAction = new QAction("Test action", this);
// Neither of this work in Qt5 but do work in Qt4
testAction->setShortcut(QKeySequence(tr(":")));
//testAction->setShortcut(QKeySequence(Qt::Key_Colon));
connect(testAction, SIGNAL(triggered()), this, SLOT(performTestAction()));
addAction(testAction);
}
MainWindow::~MainWindow()
{ }
void MainWindow::performTestAction()
{
QMessageBox messageBox;
messageBox.setText("The action has been executed.");
messageBox.exec();
}
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
#-------------------------------------------------
#
# Project created by QtCreator 2013-04-03T10:23:58
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = colontest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
#-------------------------------------------------
#
# Project created by QtCreator 2013-04-03T10:23:58
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = colontest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
To copy to clipboard, switch view to plain text mode
Bookmarks