Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.1k Topics 77.6k Posts
  • ListView changes size when placed on Page with header

    Solved
    7
    0 Votes
    7 Posts
    640 Views
    J
    @Justin-Steventon I am going to mark this as resolved. The final solution, which at least handles the scenarios I am interested in: ListView { width: parent.width Component.onCompleted: height = parent.height Connections { target: appWindow // main app window onHeightChanged: listView.height = parent.height } ... }
  • Newb: How to access C++ QAbstractListModel from child Qml item

    Solved
    6
    0 Votes
    6 Posts
    1k Views
    G
    @dgallagher219 Turns out, your suggestion still works! It's easy to get off track. Thanks.
  • 0 Votes
    2 Posts
    1k Views
    jeanmilostJ
    Finally I searched a while by myself, and I think I may answer my own question. Although I couldn't completely resolve my issue, I noticed that the answer is hidden in the other MouseArea events. For example, by handling the onPressed event and adding the mouse.accepted in several key locations, I could let the component take care of the scrolling when the left mouse button is pressed, whereas the right click opens a popup menu. My conclusion is that there is no ready-to-use way, i.e there is no parameter to activate in the MouseArea itself which may resolve this kind of issue, and the solution is a good balance between activating different parameters in the different functions.
  • Resize Scalebar on Zoomin or Zoom out

    Solved
    2
    0 Votes
    2 Posts
    239 Views
    S
    Got solution by setting map.scale to the width of scale bar
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    21 Views
    No one has replied
  • How is the QWidget::update() defined in QML?

    Solved
    2
    -1 Votes
    2 Posts
    192 Views
    mrjjM
    Hi Its not. QML uses a scene graph and its not same system as QWidgets. Maybe if you add some details to the questions, people can help you out. https://stackoverflow.com/questions/50944508/how-can-i-trigger-an-explicit-ui-update-in-qml
  • Why does GroupBox not have a Border attribute in QML?

    Solved
    8
    0 Votes
    8 Posts
    2k Views
    GrecKoG
    I believe it isn't. GroupBox only handles the visual logic (properties and positionning). The painting is done by its background item, its contentItem item and label item. Generally controls are a skeleton and delegate the painting to their child item
  • Does "playbackRate" property in Audio component work at all?

    Unsolved
    5
    0 Votes
    5 Posts
    520 Views
    A
    @fcarney Audio { source: "file:///home/amir/Downloads/beautiful.mp3" playbackRate: 0.5 onStatusChanged: play() } Mine isn't working. I tried different values on playbackRate but it plays normal speed. Xubuntu18.04 / Qt 5.12.7
  • QML webEngineView component works in standalone app, but not in QML Stack View app.

    Solved
    10
    0 Votes
    10 Posts
    1k Views
    P
    I had to instantiate my qml component that contains WebEngineView in the qml files where the StackView is used before I call it to be pushed by stackview.
  • How to add Points in QtLocation map

    Solved
    5
    0 Votes
    5 Posts
    709 Views
    S
    Hi, It did work, thank you :)
  • Is there a QtQuick component for taking screenshots?

    Solved
    4
    0 Votes
    4 Posts
    397 Views
    sierdzioS
    @RobM said in Is there a QtQuick component for taking screenshots?: Can grabToImage() do that? As far as I understand - yes. But I don't think I've ever tried it ;-) Just remember to call it on some top-level Item you have so that it captures your whole app and not some tiny part of it.
  • Labs Menubar not working properly

    Solved
    2
    0 Votes
    2 Posts
    418 Views
    J
    Turns out at least one menuItem is required in a Menu for the menu to show up. Because "Emoji & Symbols" is added to Edit automatically by Mac, the Edit menu does show up, but none of the others do. I've added my new code below that works fine. Also note that because the "About" menuItem normally shows up under the application Menu, that is where it is placed and because that's the only menuItem in the File menu, the File menu doesn't need to show up. (This is how it should be - see image after code.) ApplicationWindow { id: window visible: true visibility: "Maximized" width: 900 minimumWidth: 900 height: 700 minimumHeight: 700 title: qsTr("Crop Face") Labs.MenuBar { id: menuBar Labs.Menu { id: fileMenu title: qsTr("File") Labs.MenuItem { text: qsTr("&About") // onTriggered: Qt.quit() } } Labs.Menu { id: windowMenu title: qsTr("&Window") Labs.MenuItem { text: qsTr("&Minimize") //onTriggered: messageDialog.show(qsTr("Open action triggered")) } Labs.MenuSeparator{} Labs.MenuItem { text: qsTr("Scroll Up") //onTriggered: messageDialog.show(qsTr("Open action triggered")) } Labs.MenuItem { text: qsTr("Scroll Down") //onTriggered: messageDialog.show(qsTr("Open action triggered")) } } Labs.Menu { id: helpMenu title: qsTr("&Help") Labs.MenuItem { text: qsTr("&View Website") //onTriggered: messageDialog.show(qsTr("Open action triggered")) } } } [image: 25d9493c-e56c-4868-b867-0d642f32d5a3.png]
  • How to add Items dynamically to a Row? (in javascript)

    Solved
    13
    0 Votes
    13 Posts
    2k Views
    mbruelM
    @GrecKo said in How to add Items dynamically to a Row? (in javascript): state: barIndex === toolBar.selectedIndex ? "Selected" : "Inactive" onClicked: toolBar.selectedIndex = barIndex Hum I don't catch something.... The "state binding" doesn't seem to work correctly. When I click on a button, so the selectedIndex "main variable" is set to the index of my button but then the state of the other buttons is not updated due to the change of the value of selectedIndex. What in your solution would trigger that? (What my changeMainMenu is actually doing) Put that information in your model instead Cool will do, it sounds better but for now it is just a mock, I would get this info from C++. Hum, still for the initialization I could use that ListModel. I didn't read the QML model view framework yet... Sorry if I'm being a purist, I just want to share my vision of how one should write QML ;) don't be sorry, that's exactly what I'm looking for, get the best practices asap. Thanks for helping ;) I should also mention that I'm not a fan of the state property, but that's more opinion based. well I'm not a big fan either of states but I saw that in an example and it seems the easiest way to use Transitions. // an array of JS objects would work here too how you do that? Otherwise for the mainArea I used a Loader that is reloaded in my changeMainMenu function. How would this work with your solution? Here is my full main.qml: import QtQuick 2.12 import QtQuick.Window 2.12 Window { id: root visible: true width: 400 height: 600 title: qsTr("my QML app!") property int toolBarIndex : 0 property int toolBarHeight : 50; property int toolBarSpacing : 15; property int toolBarMargin : 20; property int toolBarButtonWidth : 50; property int headerButtonSize : 30; property int mainMargin : 20; // property var menuList : ["home", "mail", "compas", "stack", "profile"] ListModel { id: toolBarModel ListElement { name : "home" ; badge: "0" ; color: "lightgreen" } ListElement { name : "mail" ; badge: "3" ; color: "lightblue" } ListElement { name : "compas" ; badge: "0" ; color: "lightgray" } ListElement { name : "stack" ; badge: "12" ; color: "lightyellow" } ListElement { name : "profile" ; badge: "0" ; color: "ivory" } } Rectangle { id: background anchors { fill: parent; margins: 0; } color: "green" Image { source: "img/bg.png"; fillMode: Image.Stretch; anchors.fill: parent; opacity: 1 } } Loader { id: mainArea anchors { top: parent.top left: parent.left topMargin: mainMargin + headerButtonSize / 2; bottomMargin: mainMargin leftMargin: mainMargin rightMargin: mainMargin } width: parent.width - 2*mainMargin height: parent.height - 2*mainMargin - toolBarHeight - toolBarMargin } ToolBarButton { id: search anchors { top: parent.top left: parent.left margins: mainMargin; } width : headerButtonSize height: headerButtonSize imagePath : "img/search.png" state : "Inactive" selectable: false } ToolBarButton { id: chat anchors { top: parent.top right: parent.right margins: mainMargin; } width : headerButtonSize height: headerButtonSize imagePath : "img/chat.png" state : "Inactive" selectable: false } Text { text: title anchors { top: parent.top horizontalCenter: parent.horizontalCenter topMargin: mainMargin; } color: "#ff0000" font.pointSize: 24 font.bold: true } function changeMainMenu(selectedMenu){ console.log("New idx: "+selectedMenu) for (var i = 0; i < toolBar.children.length; ++i) { if (i !== selectedMenu) toolBar.children[i].state = "Inactive"; } mainArea.setSource("SimpleMainArea.qml"); mainArea.item.lbl.text = toolBarModel.get(selectedMenu).name;//menuList[selectedMenu]; mainArea.item.color = toolBarModel.get(selectedMenu).color; } Row { id: toolBar anchors { bottom: parent.bottom bottomMargin: toolBarMargin; horizontalCenter: parent.horizontalCenter } height : toolBarHeight spacing: toolBarSpacing Repeater { model: toolBarModel; //menuList ToolBarButton { id: button height: toolBar.height width: toolBarButtonWidth // imagePath: "img/" + model.modelData + ".png" imagePath: "img/" + model.name + ".png" barIndex: model.index // state: root.toolBarIndex === barIndex ? "Selected" : "Inactive" // onSelected: root.toolBarIndex = barIndex state: barIndex === root.toolBarIndex ? "Selected" : "Inactive" onSelected: changeMainMenu(barIndex) } } Component.onCompleted: { for (var i = 0; i < toolBar.children.length; ++i) toolBar.children[i].setBadge(toolBarModel.get(i).badge); } } Component.onCompleted: { changeMainMenu(0); } } The SimpleMainArea.qml import QtQuick 2.0 import QtQuick.Controls 2.14 Rectangle { property alias lbl: lbl radius: 10 opacity: 0.8 Text { id: lbl anchors { horizontalCenter: parent.horizontalCenter verticalCenter: parent.verticalCenter; } text: "not set..."; } } and my ToolBarButton.qml so you can tell me if you see bad practices ;) import QtQuick 2.12 import QtQuick.Controls 2.14 Item { id: button property string imagePath; property int barIndex : 0; property bool selectable : true; property color color: "transparent" property double opacityInactive: 0.2 property double opacityHover : 0.4 property double opacitySelected: 1 property int borderWidth : 0 property int borderRadius: 0 property string previousState: "Inactive"; property color badgeColor : "#ec3e3a"; // redish color (exactly the one used in OS X 10.10) // Allow the programmer to define the text to display. // Note that this control can display both text and numbers. // property alias badgeText: badgeLbl.text signal selected(int idx); //RectangItemle to draw the button Rectangle { id: rect anchors.fill: parent radius: borderRadius color: button.enabled ? button.color : "grey" border.width: borderWidth border.color: "black" opacity: opacityInactive Image { id: img anchors.fill: parent; source: imagePath; fillMode: Image.PreserveAspectFit; } } Rectangle { id: badge visible: false smooth: true // Create an animation when the opacity changes Behavior on opacity {NumberAnimation{}} // Setup the anchors so that the badge appears on the bottom right // area of its parent anchors.right: rect.right anchors.top: rect.top // This margin allows us to be "a little outside" of the object in which // we add the badge // anchors.margins: -parent.width / 5 + device.ratio(1) color: badgeColor // Make the rectangle a circle radius: width / 2 // Setup height of the rectangle (the default is 18 pixels) height: 18 // Make the rectangle and ellipse if the length of the text is bigger than 2 characters width: badgeLbl.text.length > 2 ? badgeLbl.paintedWidth + height / 2 : height // Create a label that will display the number of connected users. Label { id: badgeLbl color: "#fdfdfdfd" font.pixelSize: 9 anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter // We need to have the same margins as the badge so that the text // appears perfectly centered inside its parent. anchors.margins: parent.anchors.margins } } //Mouse area to react on click events MouseArea { hoverEnabled: true anchors.fill: button onEntered: { button.previousState = button.state; if (button.state != 'Selected') button.state='Hover'; } onExited : { button.state = previousState; } onClicked: { if (selectable) { button.previousState = 'Selected'; button.state = 'Selected'; } button.selected(button.barIndex); } } function setBadge(msg) { if (msg !== "" && msg !== "0") { badge.visible = true; badgeLbl.text = msg; badge.width = badgeLbl.text.length > 2 ? badgeLbl.paintedWidth + badgeLbl.height / 2 : badgeLbl.height; } else badge.visible = false; } function clearBadge() {badge.visible = false;} //change the color of the button in differen button states states: [ State { name: "Inactive" PropertyChanges { target : rect opacity: opacityInactive } }, State { name: "Hover" PropertyChanges { target : rect opacity: opacityHover } }, State { name: "Selected" PropertyChanges { target : rect opacity: opacitySelected } } ] state: previousState; //define transmission for the states transitions: [ Transition { from: ""; to: "Hover" OpacityAnimator { duration: 200 } }, Transition { from: "*"; to: "Selected" OpacityAnimator { duration: 10 } } ] } Edit: here is a small video of the desired behaviour Edit2: my commented // state: root.toolBarIndex === barIndex ? "Selected" : "Inactive" // onSelected: root.toolBarIndex = barIndex is not stable, it is working the first time but then it seems the change of root.toolBarIndex doesn't impact all the buttons.. Any idea why?
  • Z-Order for QML component loaded from C++

    Solved
    12
    0 Votes
    12 Posts
    2k Views
    H
    @GreckKo Thank you for your answer and sorry for the (announced) break. I tried your solution and it worked. Hint: since the QQuickItem class has no member contentItem(), I used the following code: qobject_cast<QQuickItem*>(rootObjects[0]->findChild<QObject*>("Page"))->childItems().first() to get the content item.
  • How to get content of a single row based on a C++ QList model in QML?

    Solved
    2
    0 Votes
    2 Posts
    251 Views
    sierdzioS
    Highlight is not part of the delegate so it does not get to see it's properties. You can rewrite your code to include the highlight in your delegate, though.
  • How to import external 3D object in Scene3D in QML ?

    Unsolved
    2
    0 Votes
    2 Posts
    263 Views
    S
    Do you really need Scene3D? Give QtQuick 3D a try https://doc.qt.io/qt-5/qtquick3d-index.html Otherwise post some code, then somebody can help you.
  • ListView with sections

    Solved
    3
    0 Votes
    3 Posts
    325 Views
    M
    Hi It worked @LeLev . Thanks a lot for your suggestion.
  • swipeview setcurrentindex not changing the view

    Unsolved
    2
    0 Votes
    2 Posts
    242 Views
    J.HilkJ
    @Gibbz can you show the code of your swipe view, that is not working?
  • How to print model info in qml console log?

    Unsolved
    1
    0 Votes
    1 Posts
    313 Views
    No one has replied
  • Unable to edit QSqlTableModel from QML

    Unsolved qsqltablemodel sqlite model model-view
    4
    0 Votes
    4 Posts
    1k Views
    sierdzioS
    @daljit97 said in Unable to edit QSqlTableModel from QML: , Qt::EditRole); Then you should probably pass the role and not editRole, otherwise model won't know which column to update.