Le mercredi 10 juin 2015 23:01:33, Jason H a écrit : > Ah, true. That was something I added in to test the width of the text. > But that doesn't explain why the text is not centered in it's parent, aka > "something". At the level of the Text, parent and "something" should be > equal, and both should work.
If you look closely at the documentation of Window and QuickWindow, you will notice that at the level of text parent equals something.contentItem. This contentItem property holds the invisible Item to which all Window child items are appended. > > Sent: Wednesday, June 10, 2015 at 4:52 PM > From: "Jérôme Godbout" <jer...@bodycad.com> > To: "Jason H" <jh...@gmx.com> > Cc: "interest@qt-project.org" <interest@qt-project.org> > Subject: Re: [Interest] What about this simple QML is broken? > The Rectangle is not a direct parent or sibling of id something, there's > Text in between. > On Wed, Jun 10, 2015 at 4:48 PM, Jason H <jh...@gmx.com> wrote: > I sat down today to teach someone QML and it didn't work as expected. I'm on > Linux usually, this person was on Windows 8, using a 32 bit Mingw. I'm > pretty confident in my QML abilities, now with mobile apps on both App > stores, and many other utilities not published. > > At issue is the simple property of using ids. When using parent, it works, > but anything using the id ("something" in this example) fails. We tried > ApplicationWindow, Window, Rectangle as the root element. When using the > Window, we get "Unable to assign QQuickWindowQmlImpl to QQuickItem". In all > other root elements it fails silently. > > Am I losing my mind? Code below - > > import QtQuick 2.4 > import QtQuick.Controls 1.3 > import QtQuick.Window 2.2 > import QtQuick.Dialogs 1.2 > > Window { > id: something > width: 500; > height: 200 > color: "lightgray" > visible: true > > Text { > id: helloText > text: "Hello world!" > y: 30 > anchors.horizontalCenter: something.horizontalCenter // won't be > horizontally centered unless "parent" font.pointSize: 24; > font.bold: true > Rectangle{ > anchors.fill:something // won't appeat unless "parent" > color:"red" > > } > } > } > > ----- > Starting > C:\Projects\build-Tutorial-Desktop_Qt_5_4_1_MinGW_32bit-Debug\debug\Tutoria > l.exe... > > QML debugging is enabled. Only use this in a safe environment. > > qrc:/main.qml:21:26: Unable to assign QQuickWindowQmlImpl to QQuickItem > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest -- Unai IRIGOYEN
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest