add qml item to Qt3DQuickWindow - qt

as you know Qt3DQuickWindow is a customized window that generated to show 3d entity on 3d scene and is a best alternative for 3dScene that can load all material independent to his implantation. (ability that 3dscene can not do in related to alpha and many other customize material)
at this time i want show a 3d scene on Qt3DQuickWindow and show my qml item on top of 3d scene and 3d environment but there is no QQmlEngine in Qt3DQuickWindow for add my qml item to them .
is there any way can i overlay on top on qml 3d scene.
tnx.

Use the View3D QML type which allows you to embed 3D Content into a QQmlEngine Window
main.qml
import QtQuick 2.14
import QtQuick.Window 2.12
import QtQuick3D 1.14
Window {
width: 1280
height: 720
visible: true
View3D {
/* put your 3d scene here */
}
/* overlay item */
Rectangle {
width: 500
height: 200
anchors.margins: -10
color: "#e0e0e0"
border.color: "#000000"
border.width: 1
opacity: 0.8
}
}

Related

How to draw element above drawer?

I am trying to place a button above a drawer, like in Windows Calculator:
but it doesn't work.
Any solutions for this?
UPD: I've updated this post and added an example gif that shows what I'm trying to achieve.
ToolButton {
id: drawerButton
width: 32
height: 32
// trying to place above this object
z: 100
anchors {
left: drawerPopUp.left
leftMargin: 5
top: drawerPopUp.top
topMargin: 5
}
}
Drawer {
id: drawerPopUp
// trying to place below this object
z: -1
width: root.width * 0.35
height: root.height
edge: Qt.LeftEdge
interactive: true
}
From the Qt documentation you can read that the Drawer automatically reparents itself to Overlay, which is above all the other elements. Therefore you would need to add a button to the overlay itself as well.
import QtQuick.Controls 2.4
ApplicationWindow {
...
ToolButton {
...
parent: Overlay.overlay
...
}
}
This might get awkward if you are doing more complex stuff, so you might have to copy the button, one in the normal way and one on the overlay

How to implement drop down color picker in Qml

I see that QML provides color dialogs out of which i can pick a color , on click of a button i can launch this color picker dialogs what if dont want the color picker dialog where on click of a button i want to show the same color picker dialog but as a drow down, something like this.
if i have to add the dialog in an overlay object? can you give me an example as to how to add it?
i have tried this and it still opens as a seperate dialog
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Dialogs 1.3
//import Qt.labs.platform 1.1
import QtQuick.Controls 2.15
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Rectangle{
id: rect1
height: 50
width: 100
color: "red"
anchors.centerIn: parent
}
Button{
id:b1
width: 50
height: 50
anchors.left: rect1.right
anchors.verticalCenter: parent.verticalCenter
text: "V"
onClicked: {
console.log("launch color picker as an overlay")
popup.open()
colorPicker.visible = true
}
Popup{
id: popup
parent: Overlay.overlay
x: Math.round((parent.width - width) / 2) + 25
y: Math.round((parent.height - height) / 2) + 50
height: 200
width: 150
ColorDialog{
id:colorPicker
}
}
}
}
Overlay is for popups:
A window overlay for popups.
Overlay provides a layer for popups, ensuring that popups are displayed above other content...
As #JarMan rightly pointed out, if you use ColorDialog, it will always be shown as a separate dialog.
If you want the color picker to be shown in the same window as a drop down, then you have to implement the color picker component and control its visibility based on user actions.
You can implement your own version of color picker component or you could reuse any existing component.

QML - How to have an animating background?

I want to have a rectangle that has a background animation.
take a look at this
codepen.io/shshaw/pen/DxJka
How can I set this as my rectangle background so that it shows this animation in my application?
I want to be able to "load" premade css animations like the one in the link.
If you think to use css, you can use a WebView and in this WebView you can load a html file from resource that read css file from resources too
Within QML there is the possibility to use particle emitters, see Qt Docs for some information. The following should get you going a bit.
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.4
import QtQuick.Particles 2.0
Item {
Rectangle {
color: "#F9A72B"
anchors.fill: parent
}
ParticleSystem { id: particles }
ImageParticle {
system: particles
source: "qrc:/cloud.svg"
alpha: 0.4
alphaVariation: 0.2
}
Emitter {
system: particles
emitRate: 1
lifeSpan: 70000
velocity: PointDirection { x: -10; xVariation: -5; }
size: 20
sizeVariation: 10
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 5
}
}
Obviously, you will have to play with the parameters to get it to your liking.

Blur part of background image in QML/Qt

I'm fairly new to QML/Qt. Basically I would like to know how to apply a blur to the inside of the white rectangle seen on the photo below and only the inside so that it blurs the part of the background image within the rectangle. I tried doing this in a normal Qt project but don't think its possible without using QML.
It's possible. Use ShaderEffectSource item:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.12
import "qrc:/"
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Image {
id: bug
anchors.fill: parent
width: 32
height: 32
source: "qrc:/Original_bug.png"
ShaderEffectSource{
id: shader
sourceItem: bug
width: 128
height: 128
anchors{
right: parent.right
rightMargin: 32
verticalCenter: parent.verticalCenter
}
sourceRect: Qt.rect(x,y, width, height)
}
GaussianBlur {
anchors.fill: shader
source: shader
radius: 8
samples: 4
}
}
}
Using sourceRect property you can specify an area to be blurred.
There are some issues when resizing the source image. This example works good only for static one.

How to make rectangle height fill ScrollView

I have the following QML code:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
Window {
id: win
width: 1024
height: 768
visible: true
ScrollView {
id:scrollView
anchors.fill: parent
Rectangle{
id:rect
z:5
color:"red"
width: 2048
height: win.height
border{
color: "black"
width: 2
}
}
}
}
In this code the larger Rectangle makes the horizontal scrollbar correctly appear. However, since the scrollbar takes some height from the window, the vertical scrollbar appears too.
How can I make the Rectangle fill only available space in my ScrollView so that vertical scrollbar won't show up? Using something like win.height - <someNumber> is not acceptable. Adding verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff is also not acceptable cause it hides some content on bottom of rect.
Generally speaking ScrollView is not meant for such usage. It is more a container to lay out items and have them shown through the provided scrollbar. Binding loops can pop here and there if bindings are not properly set. Also Flickable + a custom scrollbar (e.g. the ones available here) can perfectly fit your needs.
That said, viewport property provides the desired (cross-platform) workaround for the problem. The documentation states:
The viewport determines the current "window" on the contentItem. In other words, it clips it and the size of the viewport tells you how much of the content area is visible.
Hence the height of the child Item can be set according to the height of the viewport. A final simple example with an Image (cute kitty incoming) would look like this:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
Window {
id: win
width: 300
height: 300
visible: true
ScrollView {
id:scrollView
anchors.fill: parent
Image{
height: scrollView.viewport.height
source: "http://c1.staticflickr.com/9/8582/16489458700_c9d82954b7_z.jpg"
}
}
}

Resources