I have a problem with Layout.fillWidth property in the following code:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls.Material 2.0
RowLayout {
spacing: 40
Rectangle {
color:"#39c605"
height:width
Layout.fillWidth: true
}
Rectangle {
color:"#39c605"
Layout.fillWidth: true
height:width
}
Rectangle {
color:"#39c605"
Layout.fillWidth: true
height:width
}
}
I can see the rectangles only when I change size of the window, but it'n't visible when the app is started.
Help me, please, to resolve this issue
Add:
main.qml
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls.Material 2.0
import "pages/"
ApplicationWindow {
id:mainWindows
visible: true
width:1280
height:720
title:qsTr("abc")
Material.theme: Material.Light
Material.accent: Material.LightGreen
Material.primary: Material.Blue
StackView {
id:homeView
anchors.fill: parent
initialItem:DataList{
}
}
}
QT 5.8
Related
In qt 5.15.2 version's Qt3D, I use the property name "components" occur error! is there anyone know?
the modules I have imported to this file and .pro file sign the modules reference to the qt3d project,
this all I can do as a new learner of qml. oh that's so obscure to learn qt3d.is that mean Scene3D type have no property name "components"? but the code is used by many project.
import QtQuick 2.9
import QtQuick.Controls 2.15
import QtQuick.Window 2.2
import Qt3D.Core 2.15
import Qt3D.Render 2.15
import Qt3D.Extras 2.15
import Qt3D.Logic 2.15
import Qt3D.Input 2.15
import Qt3D.Animation 2.15
import QtQuick.Scene3D 2.15
ApplicationWindow {
id:root
signal valchange(int val)
visible: true
width: 640
height: 480
title: qsTr("Scroll")
Rectangle {
anchors.fill: parent
color: "darkred"
Scene3D {
id: scene3d
anchors.fill: parent
Camera {
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 45
aspectRatio: 16/9
nearPlane: 0.1
farPlane: 1000
position: Qt.vector3d(200, 300, 300)
upVector: Qt.vector3d(0, 1, 0)
viewCenter: Qt.vector3d(0,0,0)
}
components: [
RenderSettings {
activeFrameGraph: ForwardRenderer {
clearColor: Qt.rgba(0, 0.5, 1,1)
camera: camera
}
},
InputSettings {
}
]
PhongMaterial {
id: material
}
TorusMesh {
id: torusMesh
radius: 5
minorRadius: 1
rings: 100
slices: 20
}
Entity {
id: torusEntity
components: [torusMesh, material]
}
}
}
}```
I have a probably simple question regarding the dynamic insertion of components into a stack layout in QtQuick 2.0. See the following code:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
ApplicationWindow {
id: mainWindow
minimumWidth: 640
minimumHeight: 480
visible: true
Component {
id: stackItemComponent
Item {
Rectangle
{
color: "blue"
anchors.fill: parent
}
}
}
Item {
anchors.fill: parent
StackLayout {
id: stack
anchors.fill: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
var item = stackItemComponent.createObject(stack)
// Activating this does not solve the problem
//item.Layout.fillWidth = true
//item.Layout.fillHeight = true
}
}
}
}
The version shown inserts the simple component into the stack layout by clicking into the window but the inserted rectangle is not resized as expected. As I read in the documentation the attached properties "Layout.fillWidth" and "Layout.fillHeight" default to "true" in this type of layout so there should be no need to set them manually. But if I do so, it does not solve the problem either. It needs a manual resize of the window to to show the layout correctly.
What do I miss here?
This question is similar to - but no the same as Moving qml Item out of left side of window, because my question is about Dialogs, instead of Items in general. The difference is explained below.
I have a Qt Dialog which I want to enter the screen from the left.
The first approach I took was setting the dialogs x property to -width and then adding a Behavior on x or a manually triggered NumberAnimation.
This approach however failed, because setting negative x values is not allowed and the value gets changed to 0 immediately.
This post provides a solution for this issue, by using anchors and AnchorChanges and transitions - but only for Items.
However, the Dialog type does neither provide states, nor anchors but only coordinates.
So my question stands: How can I have a QML Dialog animate from the left outside the screen into view?
Here's a minimal code sample, that demonstrate the x property being reset to 0:
import QtQuick 2.7
import QtQuick.Controls 2.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Dialog Demo")
Dialog {
id: dialog
width: 200
height: 200
x: -width
Text {
anchors.centerIn: parent
text: "Ok?"
}
standardButtons: Dialog.Ok
onOpened: x = 100
Behavior on x { NumberAnimation{ duration: 1000 } }
}
Component.onCompleted: dialog.open()
}
You can use the enter-transition that is inherited from Popup:
import QtQuick 2.9
import QtQuick.Window 2.0
import QtQuick.Controls 2.3
Window {
id: window
visible: true
width: 600
height: 600
Dialog {
id: dialog
width: 300
height: 300
enter: Transition {
NumberAnimation { properties: "x,y"; from: -300; to: 150 }
}
}
Button {
anchors.centerIn: parent
onClicked: dialog.open()
}
}
There seems to be a Bug with the Dialog. As soon as the Dialog has some content, it fails. I have not discovered all depths of it, but wrapping everything in an Item seems to help. Compare for this:
import QtQuick 2.9
import QtQuick.Window 2.0
import QtQuick.Controls 2.3
ApplicationWindow {
id: window
visible: true
width: 600
height: 600
Dialog {
id: dialog
width: 300
height: 300
enter: Transition {
NumberAnimation { properties: "x,y"; from: -300; to: 150; duration: 5000 }
}
// HAVE A BUTTON IN THE DIALOG -> POSITIONING FAILS
Button {
anchors.centerIn: parent
}
}
Button {
text: 'open'
anchors.centerIn: parent
onClicked: dialog.open()
}
}
and
import QtQuick 2.9
import QtQuick.Window 2.0
import QtQuick.Controls 2.3
ApplicationWindow {
id: window
visible: true
width: 600
height: 600
Dialog {
id: dialog
width: 300
height: 300
enter: Transition {
NumberAnimation { properties: "x,y"; from: -300; to: 150; duration: 5000 }
}
Item { // WRAP IT IN THE ITEM -> WORKS FOR ME
anchors.fill: parent
Button {
anchors.centerIn: parent
}
}
}
Button {
text: 'open'
anchors.centerIn: parent
onClicked: dialog.open()
}
}
Inside QML MainWindow, I have Slider and ProgressBar:
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
ApplicationWindow
{
visible: true
width: Screen.width/2
height: Screen.height/2
opacity: 1.00
color: "black"
RowLayout
{
anchors.fill: parent
Slider
{
id: ueSlider
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
activeFocusOnPress: false
tickmarksEnabled: false
minimumValue: 0
maximumValue: 100
stepSize: 1
orientation: Qt.Vertical
onValueChanged:
{
ueProgressBar.value=value;
} // onValueChanged
} // Slider
ProgressBar
{
id: ueProgressBar
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
Layout.alignment: Qt.AlignRight|Qt.AlignVCenter
orientation: Qt.Vertical
indeterminate: false
onValueChanged:
{
print("ProgressBar value: "+value);
} // onValueChanged
Component.onCompleted:
{
minimumValue=ueSlider.minimumValue;
maximumValue=ueSlider.maximumValue;
value=ueSlider.value;
} // Component.onCompleted
} // ProgressBar
} // RowLayout
} // ApplicationWindow
Now, the ProgressBar is "connected" to Slider - when I change value of Slider, the ProgressBar's value changes. If I change ProgressBar's orientation to Qt.Horizontal, everything works fine, but if I change its orienation to Qt.Vertical, run example and push Slider to top (to its maximumValue), the ProgressBar does not go to 100%:
Why the hell?!
Qt Creator 5.5 doesn't syntax highlight TreeView both in Windows and MacOS.
import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
ApplicationWindow {
visible: true
width: Screen.width /2
height: Screen.height/2
TreeView {
anchors.fill: parent
}
}
TreeView is marked red underlined as if not recognized by Qt Creator but it does compile and run fine. Why is it not syntax highlighted properly?
I think it's a bug, because the required modules are properly imported.
You can suppress the warning using //#disable-check M300 before the line TreeView {
import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
ApplicationWindow {
visible: true
width: Screen.width /2
height: Screen.height/2
//#disable-check M300
TreeView {
anchors.fill: parent
}
}