QML TapHandler onLongPress get position coordinates - qt

I'm trying to show the context menu in a position where a user touched a screen with long-press. I found the TapHandler signal longPress that looks like its going to solve my problem, but it doesn't have any input parameters like eventPoint:
TapHandler {
onLongPressed: {
if (Qt.platform.os == "android" || Qt.platform.os == "ios") {
// contextMenu.x = eventPoint.position.x
// contextMenu.y = eventPoint.position.y
contextMenu.open()
}
}
}
Any suggestions or ideas?

From the docs, regarding point: HandlerPoint: "The event point currently being handled. When no point is currently being handled, this object is reset to default values (all coordinates are 0)."
https://doc.qt.io/qt-5/qml-qtquick-taphandler.html#point-prop

Related

Customize selected Item Surface3d

how i can change that item when i click on that in surface3d?
i wanna show a 3dmodel instead of that sphere or ... just wanna customize it
i searched in google and qt docs and all properties in qml but no solution...
forExample ==> MySurface.qml :
Surface3D
{
id:mySurface
Surface3DSeries
{
id:mySeries
drawMode: Surface3DSeries.DrawSurface
ItemModelSurfaceDataProxy
{
id:myModel
itemModel: ListModel{
ListElement
{
// added some points like :
idNumber:"10"
cost:"4900"
}
}
}
}
}
finally I used an Idea for finding third point ...
Note: added custome item before changing its position.
i used :
selectionMode: AbstractGraph3D.SelectionMultiSeries
onSelectedElementChanged:
{
var xPoint=mySeries.selectedPoint.x;
var yPoint=mySeries.selectedPoint.y;
var i;
if(xPoint!=-1)
{
for(i=0;i<myListModel.count;++i)
{
if(myListModel.get(i).idNumber==xPoint
&& myListModel.get(i).cost==yPoint)
{
myCustom3DItem.position=Qt.vector3d(yPoint,myListModel.get(i).height,xPoint);
break;
}
}
}
}
Thx for Answer.
we have a problem that is we not talking about a 2d scene and i need to know 3 points when clicking ...
i mean that we need know Qt.Vector3d(...) clicked on Surface3d , and when i know that i can create some CustomeItem like this
i created objects in my surface but now i want change that sphere when clicking in 3d and i cant find any property or any function that giving point(Qt.Vector3d) by clicking in surfac3d.
In addition: we cant use TapHandler or MouseArea in Surface3D ...
Thank you for trying to help .

How to get the position of a collision in Babylon.js?

Trying to make a click to move game in Babylon.js, so I'm trying to get the position on the plane that is being clicked on.
myGround.actionManager = new BABYLON.ActionManager(scene)
myGround.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function (evt) {
console.log(evt)
}));
This code does not seem to tell me the point on the parent mesh that was clicked. Is it possible to get this data?
Of course, you can use the picking collision to find the screen and world coordinates of the point you clicked on.
The simplest code can be found here:
https://www.babylonjs-playground.com/#NU4F6Y
You can also use the event from scene.onPointerObservable :
cene.onPointerObservable.add((evt) => {
if(evt.type === BABYLON.PointerEventTypes.POINTERPICK) {
console.log(evt.pickInfo.pickedPoint)
}
})
More info about picking info can be found here:
https://doc.babylonjs.com/babylon101/picking_collisions

Get wold coordinates from screen coordinates in Babylon.js

I'm not using a ground. I want to get the pickedPoint to add a mesh dynamically.
scene.onPointerDown = function (evt, pickResult) {
// if the click hits the ground object, we change the impact position
if (pickResult.hit) {
console.log('an object is picked');
} else {
console.log('get world coordinates from evt.x and evt.y');
}
};
the pickResult object has a variable called pickedPoint .
Here is a quick demo:
https://playground.babylonjs.com/#NU4F6Y#0

Keyboard events for Keys.onPressed not handled over some conditions

I'm trying to get the button event from a USB camera on an application running under linux (custom built using Yocto Project) on an embedded system. Currently I'm using Qt 5.6.3. My problem is that the code I show right below works like a charm while I run the code through SSH from my pc (both via Qt Creator and a simple shell), but if I run the same program directly on the system without using SSH nothing happens when i click the button on the camera (nor any other key from a keyboard really).
Following some examples online I used Keys.onPressed and then filter the event to get the desired behaviour. To get it globally I put the event handler inside an Item directly in my ApplicationWindow.
ApplicationWindow {
Item {
focus: true
Keys.onPressed:{
console.log(event.key)
playSound.play() //I play a sound to be sure a button is clicked
if(camera.recording && event.key === 16777466) {
//do stuff for the right key here
}
}
}
//Other elements here
}
I think it has something to do with the X server running on my system. But everything is default and I really don't know what to look for in my system to get a hint of what's not working. Any advice il really appreciated.
Maybe a problem related with Focus. What about forcing the focus after onCompleted event?
ApplicationWindow {
Item {
id: myItem
focus: true
Keys.onPressed:{
console.log(event.key)
playSound.play() //I play a sound to be sure a button is clicked
if(camera.recording && event.key === 16777466) {
//do stuff for the right key here
}
}
Component.onCompleted: {
myItem.forceActiveFocus()
}
}
Component.onCompleted: {
myItem.forceActiveFocus()
}
//Other elements here
}
can you prove to set width and height of item?
After some hours of searching it turned out it was really a problem with the X server's "active window", the solution was very simple though, I just had to add requestActivate(); on my main view just like this:
ApplicationWindow {
Item {
focus: true
Keys.onPressed:{
console.log(event.key)
playSound.play() //I play a sound to be sure a button is clicked
if(camera.recording && event.key === 16777466) {
//do stuff for the right key here
}
}
}
StackView{
id: rootView
width: 1280
height: 800
Component.onCompleted: {
requestActivate(); //THIS SOLVED THE PROBLEM
push(mainarea);
}
//Other elements here
}

Problems changing the flags of a QWidget

I have a QWidget as the child of another within my application. The task consists of putting the internal widget in full screen mode and being able to see it again in normal mode with the same button. This partly I have managed to do it in the following way:
if(!isFullScreen())
{
setWindowFlags(windowFlags() | Qt::Window);
showFullScreen();
}
else
{
setWindowFlags(windowFlags() & ~Qt::Window);
showNormal();
activateWindow();
}
The problem arises when you return to see the widget in normal mode. Things that happen:
The mouse cursor stays with pointing hand cursor.
The button to change mode remains in hover state (the background color is changed when the mouse is over)
Passing the mouse through other widget controls does not change its appearance
I have to click on the widget to fix the behavior. It's as if the widget did not receive events of any kind or something like that. I tried calling setFocus () and it did not work. I have also tried to send an event by hand in the following way but it has not worked either:
QMouseEvent my_event(QEvent::MouseButtonPress, QPointF (0, 0), Qt :: NoButton, 0, 0);
QApplication::sendEvent(this, & my_event);
Any ideas?
Thanks.
Cannot reproduce your issue on Xubuntu with Qt5.9.4.
However I did the same in my last job, and it worked correctly on all platforms. It was something like this, I think:
if(!isFullScreen())
{
setParent(0);
showFullScreen();
}
else
{
orignalParentLayout->addWidget(this); // better: insert at correct position
showNormal();
}
For this you have to add some knowledge about the parent's layout though. You could try to detect that info before going into full screen mode, but it is probably not worth the effort.
You could also try:
if(!isFullScreen())
{
logicalParent = parentWidget();
setParent(0);
showFullScreen();
}
else
{
setParent(logicalParent);
showNormal();
}
If you have no layout. You might also want to store the geometry before going to full screen.

Resources