Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
19.9k Topics 77.1k Posts
QtWS25 Last Chance
  • How to embed qml-files etc. in executable file? [solved]

    22
    0 Votes
    22 Posts
    27k Views
    N
    "look at cmake branch":https://github.com/nib952051/QtDesktopComponentsBackport/tree/cmake
  • QML date and time manipulation

    11
    0 Votes
    11 Posts
    61k Views
    A
    Qt5 and javascript are very easy to use now. If you have not upgraded, now is the time. See the Qt5 Docs.
  • [Solved] Accessing Repeater model in delegate

    3
    0 Votes
    3 Posts
    2k Views
    S
    It's been a while but I'll update what I ended up doing for anyone else interested... The reasoning behind trying to do the above was mainly that I wanted as little coupling as possible between the view (in this case a Repeater) and the delegate. Since I'm reusing my delegates in several views I didn't want to use a set view id. So basically I just provided the model as a property of the delegate component. Basically something like this: @ Repeater { model: cppModel delegate: MyComponent { delegateModel: cppModel } } @
  • QML & C++ : ReferenceError

    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • QML ListView currentItem doesn't change after a sort

    3
    0 Votes
    3 Posts
    4k Views
    B
    I figured this out... but my solution was pretty nasty. The only way to ensure the right delegate was selected was to re-check which one was selected every time the layout changed (since the layout obviously has to change if the items are re-sorted). Below is a snippet of what I did. There has to be a better way! Note that "modelId" is a role on the model. @Component { id: myDelegate Column { id: column Component.onCompleted: { myListView.setSelected.connect(handleSetSelected) } // If we don't disconnect from the signal the handler will still be called // on destroyed components and errors will be thrown about undefined // variables. Component.onDestruction: { myListView.setSelected.disconnect(handleSetSelected) } function setSelected() { myListView.setCurrentItem(index, modelId); } function handleSetSelected(modelIdToBeSelected) { if (modelId === modelIdToBeSelected) { setSelected(); } } // More delegate stuff... } } ListView { property int currentModelId: 0 signal setSelected(int modelId) function setCurrentItem(index, modelId) { currentIndex = index; currentModelId = modelId; } id: myListView objectName: "MyList" model: myModel delegate: myDelegate // Signal handlers Connections { target: myModel onLayoutChanged: { myListView.setSelected(myListView.currentModelId) } } }@
  • Custom C++ types and QJSEngine

    3
    0 Votes
    3 Posts
    4k Views
    C
    Hi, Sorry, I'm not too familiar with the QJSEngine stuff. With QML2 we now allow (via an undocumented interface) modules to provide their own value-types. These types are "QVariant-storable types which have sub-properties" such as QFont, QVector3D and so forth. Take a look at the valuetype related code in QtQuick2 - basically it registers a bunch of types as value types, provides load/store/copy/remove and conversion functions, etc. It's not too clean, there are hideous dragons in that code, and the interfaces are completely undocumented because they're really still meant for internal use only, but if you want to see how we did it, please feel free to check it out and try to provide your own in your own module. What we don't allow is any form of operator overloading. Hence, the valuetype mediator classes I implemented had a bunch of Q_INVOKABLE functions (for things like add/sub/mul etc). Cheers, Chris.
  • When I reinstall Qt Visual Studio Add-in , I have received an error.

    1
    0 Votes
    1 Posts
    851 Views
    No one has replied
  • Audio jumps up system mixer (linux,Qt5)

    2
    0 Votes
    2 Posts
    1k Views
    E
    What i forgot to install?
  • How to link pages in qml

    11
    0 Votes
    11 Posts
    13k Views
    D
    I know these posts were a while back but I have tried the code suggested by ngocketit and the correct qml file loads but it no longer recognises my shortcut keys - shortcut keys were fine, all I have done is load the qml files as above without modifying them. Is this expected??? The only thing being displayed is a listview, code below is what is in the file being loaded/displayed. The doubleClick on an item still works but pressing a number key to select an item in the listview does not. @import QtQuick 2.0 Rectangle { id: theMenu Component { id: menuEntryDelegate Rectangle { id: menuItemContainer width: menuHolder.width height: menuEntry.height * 1.25 anchors.top: prompts.bottom state: ListView.isCurrentItem ? "selected" : "notselected" Text { id: menuEntry font.pointSize: coreMenu.menuFontPointSize width: parent.width wrapMode: Text.WordWrap text: displayText clip: true } ....... } Rectangle { id: menuContainer width: coreMenu.menuWidth height: (50 * 9) anchors.horizontalCenter: parent.horizontalCenter anchors.top: prompts.bottom color: "purple" ListView { id: menuHolder model: menuModel anchors.fill: parent opacity: 1 header: Rectangle { width: menuHolder.width height: 50 color: "#2A51A3" Text { id: header anchors.centerIn: parent text: coreMenu.getMenuTitle() font.pointSize: 20 color: "green" width: parent.width wrapMode: Text.WordWrap } } delegate: menuEntryDelegate focus: true Keys.onPressed: { if(event.key === Qt.Key_Home)//go back to Main menu { coreMenu.displayMainMenu(); } //Ways to select a menu item else if((event.key >= Qt.Key_1 && event.key <= Qt.Key_9) || event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { if(event.key >= Qt.Key_1 && event.key <= Qt.Key_9) { menuHolder.currentIndex = event.key - Qt.Key_1; } coreMenu.displayMenu(menuHolder.currentIndex); } .............. }@
  • How to pass QAbstractListModel derived class to QML using setProperty?

    3
    0 Votes
    3 Posts
    4k Views
    K
    Thank you! I just also needed to add @Q_DECLARE_METATYPE(CListModel* )@ to .h file.
  • Need some advice: how to draw a line between two objects.

    15
    0 Votes
    15 Posts
    12k Views
    E
    Hi, I have already ued this example: http://www.developer.nokia.com/Community/Wiki/Creating_a_custom_QML_element_with_Qt and it works great. I thought about the Beziers curve, but I need to have a mousearea covering the line so it would be way more dificult. Any way, thank you all
  • [SOLVED] QML list view change item size to fit text

    8
    0 Votes
    8 Posts
    17k Views
    D
    I personally have not used .scale at all.
  • QML has like doEvents?

    3
    0 Votes
    3 Posts
    2k Views
    D
    Thanks for advice. I shall try workers script. :\
  • [Qt5] PathView flicks very very slow at some point

    1
    0 Votes
    1 Posts
    855 Views
    No one has replied
  • Save single Item as image

    4
    0 Votes
    4 Posts
    2k Views
    C
    bq. get the texture from QQuickItem::textureProvider()::texture() – textureProvider() always returns 0 Did you do "layer.enabled: true" on the item on the QML side? Otherwise as you note it won't have a texture. Make sure to only access the texture from the scene graph thread though, by connecting with a DirectConnection to QQuickView::afterRendering() (defined in QQuickWindow).
  • Fix qml item behavior

    2
    0 Votes
    2 Posts
    1k Views
    J
    The problem is that you are mixing the parent with the "parent" id. Try this: (oh and it is spelled "length" :) @import QtQuick 2.0 Rectangle { width: 500 height: 500 id: root Component { id: squareComponent Rectangle { property int sideLength: 500 width: sideLength height: sideLength color: "orange" MouseArea { anchors.fill: parent onClicked: { var first = squareComponent.createObject(root) var second = squareComponent.createObject(root) var third = squareComponent.createObject(root) var fourth = squareComponent.createObject(root) var sideLength = parent.sideLength / 2 first.sideLength = sideLength second.sideLength = sideLength third.sideLength = sideLength fourth.sideLength = sideLength var x = parent.x var y = parent.y console.log(x, y) first.x = x first.y = y first.color = "red" console.log("first", first.x, first.y) second.x = first.x + sideLength second.y = first.y second.color = "orange" console.log("second", second.x, second.y) third.x = first.x third.y = first.y + sideLength third.color = "blue" console.log("third", third.x, third.y) fourth.x = first.x + sideLength fourth.y = first.y + sideLength fourth.color = "black" console.log("fourth", fourth.x, fourth.y, "\n\n") parent.sideLength = 0 } } } } Component.onCompleted: squareComponent.createObject(root) } @
  • Using FocusScope

    4
    0 Votes
    4 Posts
    2k Views
    T
    That makes a lot of sense and indeed things fall into place a bit more, thanks Jens!
  • Throwing a script exception from C++ (QtQuick 2.0)

    1
    0 Votes
    1 Posts
    943 Views
    No one has replied
  • Problem with adding custom qml module

    3
    0 Votes
    3 Posts
    1k Views
    S
    I made my own qml module earlier today. What I did was to set the environment variable QML2_IMPORT_PATH to the absolute search path to my module folder. It's important that you set a global environment variable. This because when running your qml from Qt Creator you don't seem to run it as your user. I'm on a mac so I set it in the /etc/launchd.conf file as such setenv QML2_IMPORT_PATH /path/to/your/module
  • [Solved] Strange behavior of Qml ListView

    5
    0 Votes
    5 Posts
    3k Views
    D
    [quote author="Jens" date="1361264701"]My guess is that your View is completed before the model has fetched any data. The XMLListModel is asynchronous so when you position the view at row 15, there might not be any rows to position at yet. You might instead want to move the positionViewAtIndex to: XmlListModel { onStatusChanged: if (status == XmlListModel.Ready ) ... }[/quote] Thank you very much, that was the problem ( I didn't know.XmlListModel is asynchronous). So everything works when I call: @onStatusChanged: if(status==XmlListModel.Ready) { listView.positionViewAtIndex(15, ListView.Beginning) }@