Unable to assign [undefined] to int during customizing ScrollBar
-
wrote on 30 Jul 2023, 09:18 last edited by
Here is code. This code is adapted from qt doc.
import QtQuick import QtQuick.Controls Window { width: 300 height: 300 visible: true ScrollView { id: control anchors.fill: parent Text { text: "ABC" font.pointSize: 224 } ScrollBar.vertical: ScrollBar { height: control.availableHeight parent: control x: control.mirrored ? 0 : control.width - width y: control.topPadding active: true contentItem: Rectangle { implicitWidth: 6 implicitHeight: 100 radius: width / 2 color: "#c2f4c6" } } } }
When I hovered scroll bar, an error occurred
qrc:/qt-project.org/imports/QtQuick/Controls/Windows/ScrollBar.qml:33:49: Unable to assign [undefined] to int
And I cannot open
qrc:/qt-project.org/imports/QtQuick/Controls/Windows/ScrollBar.qml
, so I have no idea about the reason why I meet this problem. -
Here is code. This code is adapted from qt doc.
import QtQuick import QtQuick.Controls Window { width: 300 height: 300 visible: true ScrollView { id: control anchors.fill: parent Text { text: "ABC" font.pointSize: 224 } ScrollBar.vertical: ScrollBar { height: control.availableHeight parent: control x: control.mirrored ? 0 : control.width - width y: control.topPadding active: true contentItem: Rectangle { implicitWidth: 6 implicitHeight: 100 radius: width / 2 color: "#c2f4c6" } } } }
When I hovered scroll bar, an error occurred
qrc:/qt-project.org/imports/QtQuick/Controls/Windows/ScrollBar.qml:33:49: Unable to assign [undefined] to int
And I cannot open
qrc:/qt-project.org/imports/QtQuick/Controls/Windows/ScrollBar.qml
, so I have no idea about the reason why I meet this problem.@Kamichanw Which line is 33?
-
Here is code. This code is adapted from qt doc.
import QtQuick import QtQuick.Controls Window { width: 300 height: 300 visible: true ScrollView { id: control anchors.fill: parent Text { text: "ABC" font.pointSize: 224 } ScrollBar.vertical: ScrollBar { height: control.availableHeight parent: control x: control.mirrored ? 0 : control.width - width y: control.topPadding active: true contentItem: Rectangle { implicitWidth: 6 implicitHeight: 100 radius: width / 2 color: "#c2f4c6" } } } }
When I hovered scroll bar, an error occurred
qrc:/qt-project.org/imports/QtQuick/Controls/Windows/ScrollBar.qml:33:49: Unable to assign [undefined] to int
And I cannot open
qrc:/qt-project.org/imports/QtQuick/Controls/Windows/ScrollBar.qml
, so I have no idea about the reason why I meet this problem.wrote on 30 Jul 2023, 10:47 last edited byYou have an integer number (like size) that is not defined properly.
if it's not defined, define it
if it is defined, make sure it's defined properly
radius width is not defined, it's width(0) divided by 2
for x and Y I would use anchors.right: parent.right
control.width - width makes no sense math wise, x position being the width of the scrollview box makes no sensejust rewrite it until you get it working to help yourself understand
-
@Kamichanw Which line is 33?
-
@Kamichanw Which line is 33?
wrote on 31 Jul 2023, 04:29 last edited by Kamichanw@Lahearle I've tried to define
width
, but it still didn't work. In fact, even I just set an empty rectangle ascontentItem
of ScrollBar, like this:contentItem: Rectangle {}
The error occurred still occurred when I hovered the
ScrollBar
. -
@Lahearle I've tried to define
width
, but it still didn't work. In fact, even I just set an empty rectangle ascontentItem
of ScrollBar, like this:contentItem: Rectangle {}
The error occurred still occurred when I hovered the
ScrollBar
.wrote on 31 Jul 2023, 04:30 last edited by -
wrote on 31 Jul 2023, 04:33 last edited by Kamichanw
@LS-KS I cannot understand... The
width
we discussed earlier is the width ofScrollBar
. AndScrollBar
is assigned toScrollBar.vertical
which is a attached property ofScrollView
. It shouldn't be a child item ofScrollView
.What's more, when the
Rectangle
is assigned tocontentItem
, it doesn't have attached property namedLayout
. -
@sierdzio I don't know. As you can see, the error message shows that error occurred in
qrc:/qt-project.org/imports/QtQuick/Controls/Windows/ScrollBar.qml
which is a qt internal file.@Kamichanw said in Unable to assign [undefined] to int during customizing ScrollBar:
@sierdzio I don't know. As you can see, the error message shows that error occurred in
qrc:/qt-project.org/imports/QtQuick/Controls/Windows/ScrollBar.qml
which is a qt internal file.Well, but looking at it will tell you which property assignment has failed. Then you will know which object in your code is
undefined
. -
@LS-KS I cannot understand... The
width
we discussed earlier is the width ofScrollBar
. AndScrollBar
is assigned toScrollBar.vertical
which is a attached property ofScrollView
. It shouldn't be a child item ofScrollView
.What's more, when the
Rectangle
is assigned tocontentItem
, it doesn't have attached property namedLayout
.wrote on 31 Jul 2023, 06:42 last edited by@Kamichanw
If you cannot track down which item it is in your code, maybe try commenting each one out till you find out? -
@LS-KS I cannot understand... The
width
we discussed earlier is the width ofScrollBar
. AndScrollBar
is assigned toScrollBar.vertical
which is a attached property ofScrollView
. It shouldn't be a child item ofScrollView
.What's more, when the
Rectangle
is assigned tocontentItem
, it doesn't have attached property namedLayout
.wrote on 31 Jul 2023, 06:43 last edited by@Kamichanw
I never used that ScrollBar Item so I may be wrong.
In general when you place something into a Layout object (like ScrollView) you can't use width and height but must use Layout -properties like preferredWidth etc.
You used width in your calculations. -
@Kamichanw
If you cannot track down which item it is in your code, maybe try commenting each one out till you find out? -
@Kamichanw
I never used that ScrollBar Item so I may be wrong.
In general when you place something into a Layout object (like ScrollView) you can't use width and height but must use Layout -properties like preferredWidth etc.
You used width in your calculations. -
@Kamichanw said in Unable to assign [undefined] to int during customizing ScrollBar:
@sierdzio I don't know. As you can see, the error message shows that error occurred in
qrc:/qt-project.org/imports/QtQuick/Controls/Windows/ScrollBar.qml
which is a qt internal file.Well, but looking at it will tell you which property assignment has failed. Then you will know which object in your code is
undefined
.wrote on 31 Jul 2023, 08:01 last edited by@sierdzio Yes, I hope to open that file as well, but when I click the hyperlink in QML debugger console, it shows that
I also tried to searchScrollBar.qml
in qt source directory, but there are too many file namedScrollBar.qml
so that I don't know where to start. -
@sierdzio Yes, I hope to open that file as well, but when I click the hyperlink in QML debugger console, it shows that
I also tried to searchScrollBar.qml
in qt source directory, but there are too many file namedScrollBar.qml
so that I don't know where to start.wrote on 31 Jul 2023, 08:09 last edited by@Kamichanw
Is there a directory something likeQtQuick\Controls\Windows
in the source tree? If so, how manyScrollBar.qml
files are there in that directory? -
wrote on 31 Jul 2023, 08:12 last edited by
Hey guys, I opened
C:\Qt\6.4.2\Src\qtdeclarative\src\quickcontrols2\windows\ScrollBar.qml
. I think it might be the correctScrollBar.qml
. The line 33 usescontentITem.transitionDuration
. But I cannot set in my file directly.NativeStyle.ScrollBar { // Fade a hovered-looking version of the handle // on top of the default handle when hovering it x: contentItem.x y: contentItem.y z: 1 width: contentItem.width height: contentItem.height control: controlRoot subControl: NativeStyle.ScrollBar.Handle overrideState: NativeStyle.StyleItem.AlwaysHovered opacity: controlRoot.hovered || control.pressed ? 1 : 0 visible: contentItem instanceof NativeStyle.StyleItem-- Behavior on opacity { NumberAnimation { duration: contentItem.transitionDuration } } // line 33 }
-
Hey guys, I opened
C:\Qt\6.4.2\Src\qtdeclarative\src\quickcontrols2\windows\ScrollBar.qml
. I think it might be the correctScrollBar.qml
. The line 33 usescontentITem.transitionDuration
. But I cannot set in my file directly.NativeStyle.ScrollBar { // Fade a hovered-looking version of the handle // on top of the default handle when hovering it x: contentItem.x y: contentItem.y z: 1 width: contentItem.width height: contentItem.height control: controlRoot subControl: NativeStyle.ScrollBar.Handle overrideState: NativeStyle.StyleItem.AlwaysHovered opacity: controlRoot.hovered || control.pressed ? 1 : 0 visible: contentItem instanceof NativeStyle.StyleItem-- Behavior on opacity { NumberAnimation { duration: contentItem.transitionDuration } } // line 33 }
@Kamichanw You should not customize native styles.
https://www.youtube.com/watch?v=mImptIBmWW0&t=1179s -
@Kamichanw You should not customize native styles.
https://www.youtube.com/watch?v=mImptIBmWW0&t=1179s
1/17