Wasm apparently doesn't handle keyboard shortcuts
-
Hello, I"m having trouble with the webAssemby build of the Qt C++ Application I'm currently developing. Two years ago, maybe longer, I made my first Qt C++ application and was happy to have it run on internet using WebAssembly. This app. handled 2d graphics and I used several keyboard shortcuts to ease its use, and those shortcuts worked, I mean as well using Desktop version of the app and also using its Web Assembly version that I host on github. Last week I started to add 3d support to this app, something very basic that I grabed from a fantastic guy on YouTube. The app is starting nicely but sadly I didn't manage to have its WebAssembly version responding to keyboard shortcuts that work fine on desktop version. I'm simply using QActions into my mainWindow menubar but whatever key combination that I try don't work. And I'm not able to say if it is a WebAssembly bug, I tried to compile my functional first version and it doesn't compile anymore, saying that the syntax is incorrect on build command
« C:\Qt\Tools\mingw1310_64\bin\mingw32-make.exe » -j4
It can be because I'm now using MSVC and no more MinGW and apparently the WebAssembly build process uses MinGW.I browsed all the code of my first project, looking for some parameter that need to be set for WebAssembly to handle keyboard shortcuts, but didn't find anything on the code or on the makefile (.pro file).
Are there users of WebAssembly who managed to have their code handle keyboard shortcuts with Qt 6.8.0 ? I don't remember which version I used to build my working WASM version, but it was two years ago.
-
To be more precise, the only keyboard inputs that are not handled are those of the menuBar. I can still type anything into the left tableWidget edit items. Maybe is it only that menu shortcuts are filtered/blocked when using basic GraphicScene/GraphicViews and that there's something to add to them by reimplementing them and setting an option that is disabled by default ? Or at least maybe is there some bug on Firefox that I'm using as browser, I need to test with others browsers.
I just tested with Chrome and it has the same exact behaviour.
I also managed to convert my first project from QMake to CMake and it now creates a WASM version that runs and has the same behaviour (I mean as the new project) : keyboard shortcuts don't fire corresponding actions. For me it's a regression and it's happy that this project doesn't need any bug correction as I would need to install older versions of Qt and Emscripten to be able to compile it without functionality loss.
I'm using a customized Item class inheriting from QGraphicsPolygonItem and by adding Qt::ItemIsFocusable to its flags, I'm not able to use keyboard events on it, but what is odd is that is is only possible when the mouse cursor is opening the Menu and only the 2 shorcut turning along the X axis work. So my hypothesis is that maybe the way I create my actions and so on is wrong. Here is what I do on my main window constructor :
The menuBar and its menu entries are using QT Creator design editor, just like 3 other widgets that I need (a TableWidget and two GraphicViews, one for 3d and another for 2D)
Then on the main window constructor after setUpUI() command,
I have connect commands, one for each shortcut, like that :connect(ui->actionXD, &QAction::triggered, this, &UI::Tourner3DXD);
Two GraphicsScenes are also dynamically created for corresponding 3D and 2D views.
-
I almost got it right, the reason why the 2 actions worked is because I changed their Shortcut Context parameter value to "Application shortcut". Now I changed that for all other shortcut, and they work as well. But I still need to have the menubar selected to have them work, maybe do I need to change the QAction parent to the QGraphicsScene ?
I finally found a workaround by removing the application menu bar and instead adding toolbars at the top of the 3 widgets I'm using.
-
-
@RandomGuy For the moment I'm still investigating.
- With Application Windows MenuBar populated, my GraphicsView never receive keyboard shortcuts nor keyboard events event when I click on it to give it the focus.
- Without MenuBar and with ToolBar as first widget of my GraphicsView's parent layout, it works only if I only use simple ToolButtons, and even then, if I simply hover over one of those ToolButtons and let the tooltip appear, the GraphicsView stop receiving key events.
- If I try to add a ToolButton with its popupmode set and add a menu to it, WA crashes
- With a ComboBox instead of the ToolBar, I can have a menu remplacement but my GraphicsView doesn't receive keyboard shortcuts not keyboard events (I redefined a customGraphicsView to handle key events for that).
I'm open for any solution where a main menu (I have file options , 3d options, and 2d options and need menus, drop down buttons or combo for the user to be able to select them) is usable while the user is able to use the keyboard to move things (on the 3d view but also the 2d), and for the moment I didn't find a way to do so on WA.
-
-
Hello, I now have more details about this behaviour. First, I got rid of the menubar and shortcuts and I'm only using keyboard events from a keyPressEvent on my MainWindow class. But the problem is remaining, there are some widget interactions that stops those keyboard events to he handled even if the focus is on my 3d view. The concerned widgets are a dialog (QColorDialog) and clicked comboboxes, and anything that showed a tooltip. After their interaction I always need to press "TAB" (and also click into the 3d view, a subclassed QGraphicsView, after the dialog closes) to be able to use the keyboard. I tried to use releaseKeyboard() on those widgets grabKeyboard() on my 3d view, but it didn't work. So there is maybe a WA bug when interacting with widgets that showed a tooltip as that works fine with Desktop version.
-
For the moment I removed the QColorDialog and each time the "+" button is pressed I add a new QColor from a preloaded list, it helps keeping the editing flow fluid, but there are still moments where I still need to press TAB to be able to use the keyboard to turn the 3d model. I will maybe replace the widgets that show a tooltip by a QGraphicsScene.
-
Here's how I create my MainWindow. There's no .ui file. I create a splitter, then 4 widgets that are added to the splitter. I create 4 VBoxLayouts that are each parented with one of the 4 widgets. The first VBoxLayout is for the main menu that is a toolbar, so I add create a toolbar that I add to it as widget, the others ones have not only a toolbar but also another widget, so I create a toolbar for each of them and set it with setMenuBar(). The widgets are : for the second VBoxLayout, a TableWidget, and for the third and the fourth ones a subclassed QGraphicsView, one for 3d view and one for 2d view. All the keyboard events are handled into the MainWindow KeyPressEvent() handler. That's it. My problem is that each time the mouse hovers some widget that has a tooltip, I need to press TAB key to be able to have my keystrokes handled. What are the things I can do to get rid of that compulsory TAB press ?
-
While waiting for next update of WebAssembly, I have now compiled my application both on Windows, Linux and Mac OS, and they all run fine, no loss of keyboard handling after a tooltip has shown or a dialog opened (and closed). I also compiled and deployed WebAssembly with Windows and Mac Os and the problem appear exactly the same. I'm about to try to port my application using Dear ImGui to see if its generated WebAssembly has the same behaviour but finally I may simply port it to javascript/html trying to use my C++ code as much as possible.
-
I am having a similar issue too. In one of my views (mixed Qml and C++) I have a Node editor, where nodes can be added and connected. I used to handle the
Keys.onPressed
event and delete selected nodes and connection when Delete is pressed. This worked very well with Qt 6.6.1 in Webassembly (I use Linux). Now, when I switched to 6.8.1,Keys.onPressed
event is never generated in Webassempbly (works well on desktop). My scene receives the active focus (I am loggingonActiveFocusChanged
) but not the keyboard events.