Customize selected Item Surface3d - qt

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 .

Related

How to display model in QML with pages?

I have problem with displaying model with pages, and I can't find what is proper way to do this.
I have ListView which has model of 15 rectangles like in the picture below.
There is property currentPage which is changed when clicking the buttons. I want to be able to display:
0-4 elements in the first page
5-9 in the second
And last 5 on the third page.
I know that I can create them for example FirstPage.qml, SecondPage.qml... And use them directly, but I want to display Items from model. The ListView is not important it can be any component but I want to use model.
What is the best way to achieve this? Any idea suggestion is welcome.
ListView has a method called positionViewAtIndex() that will allow you to specify which item to scroll to. So for your case, you could do something like this:
Button {
id: previousBtn
onClicked: {
listView.positionViewAtIndex(listView.currentIndex - 5);
}
}
Button {
id: nextBtn
onClicked: {
listView.positionViewAtIndex(listView.currentIndex + 5);
}
}

QML TapHandler onLongPress get position coordinates

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

How to update ListElement (QML) value field with dynamically updating property

In the below code, the property __operatingModus_season updating every 30 seconds. But in frontend, I dont see any value or changes. Please give some heads up if i am wrong.
ListModel{
id: tileListModelBetriebsmodus
Component.onCompleted: {
if(__is_automatik_mode_ON){
tileListModelBetriebsmodus.append({"tileListSource": "../../images/HausScreen/operatingModeAuto.png",
"tileListText": getFrontendText("AUTO"),
"tileListValue": __operatingModus_season
})
}else{
tileListModelBetriebsmodus.append({"tileListSource": "../../images/HausScreen/hamburgerfinger.png",
"tileListText": getFrontendText("MANUAL"),
"tileListValue": __operatingModus_season
})
}
}
}
This way of adding items to the ListModel doesn't make them dynamic, the values are stored on the spot.
You might be able to Create Property Bindings like this:
ListModel{
id: tileListModelBetriebsmodus
Component.onCompleted: {
if(__is_automatik_mode_ON){
tileListModelBetriebsmodus.append({"tileListSource": "../../images/HausScreen/operatingModeAuto.png",
"tileListText": getFrontendText("AUTO"),
"tileListValue": Qt.binding(function() { return __operatingModus_season })
})
}else{
tileListModelBetriebsmodus.append({"tileListSource": "../../images/HausScreen/hamburgerfinger.png",
"tileListText": getFrontendText("MANUAL"),
"tileListValue": Qt.binding(function() { return __operatingModus_season }
})
}
}
}
Note I did not test this, if you would add a minimal working example I could have done so.
Amfasis' answer suggesting the use of Qt.binding() is on the right track, except Qt won't allow assigning a binding object directly to a ListElement. However, it allows assigning plain JS function objects. So you have to do it in two steps instead:
Step 1: Define your dynamically evaluated ListElement role as a JS function (tip: you can also use the arrow syntax to make this more readable), for example:
ListElement {
dynamicLabel: () => config.useLabelA ? labelA : labelB
}
Step 2: Set up a binding inside your delegate between the target item and the model role:
ListView {
delegate: Text {
Component.onCompleted: {
text: Qt.binding(model.dynamicLabel)
}
}
}
Note the need to go through Component.onCompleted as you can't do text: Qt.binding(model.dynamicLabel) directly (QML spits out an error "Invalid use of Qt.binding() in a binding declaration.").
You can't just do text: model.dynamicLabel either as that would only evaluate the JS function once at initial assignment, but not update if e.g. config.useLabelA changed. That's what you need the Qt.binding() wrapper for.
Building on Romain Pokrzywka's answer:
text: valuedUpdated() ? model.dynamicLabel : "" will be evaluated whenever value is updated. valuedUpdated() is a Q_PROPERTY, which returns true. Notify signal can be emitted whenever value is updated.

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
}

Resources