Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.0k Topics 77.4k Posts
  • Can I populate a TableView's rows with a C++ QVariantList?

    Unsolved
    4
    0 Votes
    4 Posts
    776 Views
    J
    Thanks for providing the update. I'm looking to do something similar at the moment, and am somewhat perplexed by the QAbstractItemModel approach. It seems overly complex for managing some basic data types in a QML TableView, and (from the initial research I've conducted) it seems that the 'roles' have to be pre-defined, which surely makes the use of a generic QAbstractItemModel-based class (i.e. one where the class can be instantiated for multiple QML TableViews within the one application, each with its own set of columns, etc.) either very complicated or not possible?
  • QML TableView delegate row height with multi-line text

    Unsolved
    3
    0 Votes
    3 Posts
    880 Views
    J
    I've made a bit of progress. I found this post on SO, which showed a way of producing a dynamic height for each row within the rowDelegate element: rowDelegate: Rectangle { height: (myModel.get(styleData.row).lineCount || 1) * 20 } I've modified this for my particular use case, and now have the following: rowDelegate: Rectangle { Component.onCompleted: { height = myTableModel.get(styleData.row).data.split("\n").length * 20 } } Note that in the above snippet, my 'myTableModel' refers to a ListModel (in my updated code), not the TableModel shown in my original post. The above code works, but it doesn't provide a complete solution. If my TableView were to be expanded to incorporate additional columns, a Math.max() calculation would have to be performed to process the .split("\n").length value of every single column, which doesn't seem like an efficient solution. The more pressing concern, is that this approach only caters to multi-line text strings that have explicit '\n' newline characters. The solution should also be able to account for text strings that have wrapped. Any ideas?
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    7 Views
    No one has replied
  • I have Qt Creator that has no Qt Quick Qml with C++ only with python

    Solved
    8
    0 Votes
    8 Posts
    804 Views
    M
    btw, I have another qt quick qml catergory here but I think it's different from Qt Quick Application C++ the normal which I find in tutorials I also have inquiry is Qt Qucik is relating to QML project only right? or it has another unique thing for speicifc projects? [image: 495098e5-dc64-4457-ae8d-45d9b70bc2ae.png]
  • Is there a way to create a tableview inside a button click event?

    Unsolved
    2
    0 Votes
    2 Posts
    148 Views
    N
    Im not sure what are you trying to achieve but you cant create objects like this with java script... (since button handlers are js functions and are not evaluated as qml code) , consider using a loader and a check-able button so that when the button is checked you set the loader visible or not visible (though you dont need a loader for that) or change the source component somthing like this: Item{ Button{id: someButton } Loader{ visible: someButton.checked sourceComponent:TableVIew{...} } } Also you might want to read this https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html
  • How to set Qt::WA_AlwaysShowToolTips for QML Tool Window

    Unsolved
    2
    0 Votes
    2 Posts
    258 Views
    No one has replied
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    8 Views
    No one has replied
  • Stopping camera blocks ui thread

    Unsolved
    1
    0 Votes
    1 Posts
    151 Views
    No one has replied
  • Qt QML Map Antialiasing Problem

    Unsolved
    1
    0 Votes
    1 Posts
    201 Views
    No one has replied
  • How to adjust text font size relative to parent

    Solved
    2
    0 Votes
    2 Posts
    1k Views
    N
    I have found two possible solution: instead of creating a font property we can create our custom Text and setting the font corresponding to the parent size like this: import QtQuick Text{ property real pixelSize: Theme.fPixelSizeS property bool bold: false property string fontFamily: Theme.fFamily property real minPixelSize: 10 property font _font _font.pixelSize: pixelSize _font.family: fontFamily _font.bold: bold color: Theme.textDefault font: _font anchors.verticalCenter: parent.verticalCenter wrapMode: Text.WordWrap fontSizeMode: Text.HorizontalFit; elide: Text.ElideMiddle } create a binding to the Qt.font function and provide our defaults as primitives like this: QtObject{id: defaults readonly property string fFamily: "Segoe UI Semibold" } Text {id: someText width: parent.width height: parent.height font: Qt.font({ pixelSize: someText.height / 5, fontFamily: defaults.fFamily }) minimumPointSize: 10 fontSizeMode: Text.Fit } note that the second approach for some reason makes the console very chatty.
  • JsonModel/XmlModel vs nested ListModels

    Unsolved
    1
    0 Votes
    1 Posts
    126 Views
    No one has replied
  • How to bind a delegate item property to top-level property

    Unsolved
    13
    0 Votes
    13 Posts
    2k Views
    J
    @GrecKo Thank you for this syntax suggestion!
  • Migrate Qt6 from Qt5 scenegraph

    Unsolved
    1
    0 Votes
    1 Posts
    398 Views
    No one has replied
  • Good way to completely change a page through options

    Unsolved
    1
    0 Votes
    1 Posts
    135 Views
    No one has replied
  • QML - how to add custom virtual keyboard layout?

    Unsolved
    1
    0 Votes
    1 Posts
    247 Views
    No one has replied
  • Qt6 QML QQmlApplicationEngine failed to load component error

    Unsolved
    1
    0 Votes
    1 Posts
    661 Views
    No one has replied
  • ListView section with QList<QObject*> as model not working

    Solved
    2
    0 Votes
    2 Posts
    342 Views
    fcarneyF
    Test this out with a QML ListModel with the same QML. I don't think all properties on a QObject are automatically turned into properties the ListView delegate can see. Otherwise it would pollute the delegate namespace. To get the values out of the QObject you will have to use modelData.<property>. You could try that in section.property to see if that will work. "modelData" for a "list" used as a model is the property it injects. For a "proper" model you would need to base off of QAbstractListModel or similar. Then the properties you see are defined in roleNames function. Try this to see if this is what is happening (not sure if this would work though): section.property: "modelData.label" Edit: I think I said something badly: When using a list of some sort (QList, [], etc) that is not based upon one of the abstract models. The injected delegate property is called "modelData". This would be each item from the list in that property. So in your case it would be the LandmarkViewModel object.
  • read translation text from excel sheet into QTranslator at runtime

    Solved
    8
    0 Votes
    8 Posts
    856 Views
    V
    Finally, I have implemented this using QXlsx https://github.com/QtExcel/QXlsx library for reading MS Xlsx file and store it in the below DS to load data mentioned in post image above: QMap<QString, QMap<QString, QString>> m_langTransMap; QMap<Input String,QMap<LangName,TranslatedText>> Use of Own Translator: QML: Text{ text: myTranslator.getTranslatedText( "Main Controller") + myTranslator.emptyString] } class TranslationHandler : public QObject { Q_OBJECT Q_PROPERTY(QString emptyString READ getEmptyString NOTIFY languageChanged) public: void TranslationHandler::loadTranslationData() { /// Read Excel Data /// load it into QMap emit languageChanged(); } Reference Link: https://wiki.qt.io/How_to_do_dynamic_translation_in_QML https://www.kdab.com/wp-content/uploads/stories/QmlComponentDesign-TwoWayBindingProblem-AndreSomers.pdf Read Cell Data: https://github.com/QtExcel/QXlsx/blob/master/TestExcel/extractdata.cpp https://github.com/QtExcel/QXlsx/blob/master/TestExcel/hello.cpp
  • QML Item states precedence?

    Solved
    2
    0 Votes
    2 Posts
    271 Views
    fcarneyF
    It looks like there is a precedence: import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Layouts 1.15 import QtQuick.Controls 2.15 Window { width: 640 height: 480 visible: true title: qsTr("State Precedence") Text { text: rect.state } RowLayout { anchors.fill: parent ColumnLayout { Layout.preferredWidth: 150 Layout.fillHeight: true Repeater { id: staterepeat model: 5 delegate: CheckBox { text: "state %1".arg(modelData) } Component.onCompleted: { for(let ind=0; ind<model; ++ind){ let nstate = rect.states[ind] nstate.when = Qt.binding(()=>itemAt(ind).checked) } } } } Rectangle { id: rect width: 200 height: 200 border.width: 1 states: [ State { name: "state 0" PropertyChanges { target: rect color: "red" } }, State { name: "state 1" PropertyChanges { target: rect color: "blue" } }, State { name: "state 2" PropertyChanges { target: rect color: "green" } }, State { name: "state 3" PropertyChanges { target: rect color: "yellow" } }, State { name: "state 4" PropertyChanges { target: rect color: "orange" } } ] color: "black" } } } Items that appear first in the list have precedence vs things that appear later.
  • Is command line: -platform webgl:port=xx deprecated?

    Unsolved
    2
    0 Votes
    2 Posts
    342 Views
    SGaistS
    Hi and welcome to devnet, From a quick search, QtQuick WebGL is not available at all in Qt 6 currently. See here for the comparison and explanation. Depending on what you are developing, Qt for WebAssembly might be a possibility.