i am creating a javafx application in which i am implementing touch pressed and release events. while long touch press a square box comes up as a effect for long touch event which doesn't go when i release the touch event.
in the below image you can see square box is effect of touch event, when i randomly touch screen then it goes.
below is my touch listener code
javafx.event.EventHandler<TouchEvent> buttonStartZoomInPressed = new javafx.event.EventHandler<TouchEvent>(){
public void handle(TouchEvent e)
{
startZoomIn();
}
};
buttonStartZoomIn.setOnTouchPressed(buttonStartZoomInPressed);
Related
I am working on an application to be deployed as a wasm app and a windows application.
we are using a windows 10 OS touch screen tablet and google chrome to access the web app. am using an empty new qt project to demonstrate the problem :
The onscreen Keyboard popups up regardless of focus meaning it will pop up wherever i touch the screen:
if btn is pressed
if lineedit is selected
if empty widget space is touched even though there is no focus object behind it.
i include a link to this Behaviour Video so you can see the problem.
the onscreen Keyboard popup without focus problem occurs only if i compile for webassembly, works fine on the same tablet for MSVC.
what i tried :
catch the events then ignore them using :
ui->centralwidget->installEventFilter(this);
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
//print event to qdebug
static int eventEnumIndex = QEvent::staticMetaObject.indexOfEnumerator("Type");
QString TEXT_Event = QEvent::staticMetaObject.enumerator(eventEnumIndex).valueToKey(event->type());;
qDebug()<<"TEXT EVENT="<<TEXT_Event;
if(TEXT_Event.contains("Paint")){
//dont show print event
}else{
ui->Main_PlainTextEdit->appendPlainText(obj->objectName()+"=>"+TEXT_Event);
}
if( event->type()==QEvent::MouseButtonPress|| event->type()==QEvent::MouseButtonRelease)
{
// handle on-screen keyboard
event->ignore();
event->accept();
}
return true;
}
setAttribute(Qt::WA_TransparentForMouseEvents);
not OK as it deactivates all mouse input => no interaction possible,
setAttribute(Qt::WA_AcceptTouchEvents);
This only changes the event from Mouse event to touch event.
Maybe there is an option that i need to tick in the form editor or touchscreen option that needs to be activated, maybe the way to catch and ignore event i implemented is wrong.
I don't know what i am doing wrong but all my attempts to fix this didn't work, please help guide me ?
Thank you in advance.
Here is how I solved it in Qt 5.15. To prevent the keyboard from popping up, I edited the default index.html. Bu default, there is a line:
<canvas id="qtcanvas" oncontextmenu="event.preventDefault()" contenteditable="true"></canvas>
I added inputmode="none", meaning I changed it to:
<canvas id="qtcanvas" oncontextmenu="event.preventDefault()" contenteditable="true" inputmode="none"></canvas>
What this does, is it prevent the onscreen keyboard from popping up. But note that it will not popup even when a line edit is in focus, so one must use either a physical keyboard or a custom virtual keyboard widget if typing text is required in the UI.
Hopefully it will get better in future Qt versions, I see there is currently some fixes scheduled for Qt 6.4 https://bugreports.qt.io/browse/QTBUG-83064
I am developing an on screen music keyboard using JavaFX under Kotlin. The graphics and layout are in place using Buttons with appropriate images. The buttons are added to a Group which is in a StacKPane.
I can detect simple mouse press and release events to trigger appropriate MIDI on/off messages. To this point everything is working fine except that the keyboard is monophonic (IE only able to play a single note at a time).
I wish to extend the keyboard to play multiple notes. The sequence of gesture are as follows:
Mouse press on an initial key triggers the first note. If the mouse enters an adjacent key with the button down, the original note should continue while a new note is triggered. Whenever the button is released or the mouse is no longer above any key, all notes should stop.
I have implemented something similar a decade ago using Swing but the JavaFX events do not operate the same way.
I can detect the initial mouse pressed event, however as long as the button is down, MouseEntered events are not detected when moving to another key. I have also tried MouseMoved, MouseDraggedEnterd and DragDetected with no luck. It is as if the initial MousePressed event is blocking all other events until the button is released. Any suggestions? Thanks
Code Snippet
fun setKeyListeners(b: Button, keynumber: Int) {
b.setOnMousePressed { _ ->
node as VirtualKeyboard
val velocity = 64
node.triggerOn(keynumber, velocity)
status("key: ${node.lastKeynumber} vel: ${node.lastVelocity}")
}
b.setOnMouseReleased { _ ->
node as VirtualKeyboard
node.triggerOff(keynumber)
}
// b.setOnMouseMoved { _ -> println("Moved $keynumber") }
// b.setOnMouseDragged { _ -> println("Dragged $keynumber") }
// b.setOnMouseEntered { _ -> println("Entered $keynumber") }
}
Is there a method for a JavaFX controller that gets called when the user leaves that view in the application? The opposite of the initialize() method basically.
I want to do this because I have a page that shows a webcam stream waiting for the user to press a button that takes a snapshot, and I need to close that stream if the user doesn't take a snapshot and leaves the screen. Any other ways of doing this would be appreciated too.
Thanks!
You can use the window's hiding event...
private void detachHook(final Node parent) {
parent.getScene().getWindow()
.addEventFilter(WindowEvent.WINDOW_HIDING, event -> {
//Kill your webcam stream
});
}
You will have to check if you also get the parent as we do in our application, but the window hiding event should work if a node and a scene are present.
I have an MFC button control and I am trying to handle the "OnPressed" event of it by starting a timer on click and making it go through my event in the OnTimer function. This all works fine but the focus remains on the button and if I click outside of the button area, the app carries out the OnPressed event. Any suggestions on how to kill the focus on the button when the mouse is pressed outside of the button area? My code for getting the focus and button ID.
void Dlg::OnTimer(...)
{
CWnd * pFocus = GetFocus();
int btnID = 0;
if (pFocus != NULL && pDialog->IsChild(pFocus))
btnID = pFocus->GetDlgCtrlID();
// Carry on my button pressed activity
Buttonpressed();
}
So basically I am getting the proper button press and I can carry out the desired action using the Buttonpressed() function given above. Now my problem is, once that button is pressed, it gets focus and the focus remains even after I leave the mouse and move out of the area of the button. Because of this behaviour, if I click outside of the button area, the application still thinks that I am in the mouse area and pressing the button. Is there a way I could remove focus after the mouse is moved out of the button area and then bring focus back in again when it is in the button area?
Looking forward to your suggestions.
I have a simple QGraphicsWidget, MyGraphicsWidget. Here's my mouseMoveEvent(), which seems to work fine :
void MyGraphicsWidget::mouseMoveEvent (QGraphicsSceneMouseEvent *event)
{
QPointF p = event->scenePos() - m_StartPos;
if(p.manhattanLength() < 20)
return;
//omitted drawing a rounded rect on the drag
QDrag *drag = new QDrag(event->widget());
drag->start(Qt::MoveAction);
}
The scene's dropEvent() just moves this widget to its new position, and I don't have a press/move event for the scene itself, so those should get passed on correctly to the widgets within.
However, once the drag completes, the next mouse press will be on this widget. So if I try to click and drag another widget, I'll be stuck dragging this one on accident, despite the fact that my cursor is not on this widget. I've printed out the event->pos() and event->scenePos(), and both reported that the cursor is where it appears to be (not on the widget at all). If I click once before trying to click and drag, everything works normally. Is there maybe something I need to implement within mouseReleaseEvent() or my mouseMoveEvent() ?
Thanks.
It's working now. I'm pretty sure this was the issue:
MyGraphicsWidget had another custom GraphicsWidget sitting on top of it, and in its mousePressEvent, I was calling QGraphicsWidget::mousePressEvent(event); at the start of the event. The rest of the event was never getting triggered, which was messing it all up. I moved that line to the end of the method, and everything seems okay now.