Skip to content
QtWS25 Call for Papers
  • 0 Votes
    1 Posts
    191 Views
    No one has replied
  • 0 Votes
    5 Posts
    1k Views
    C

    @JonB alright.I will remember that

  • 0 Votes
    5 Posts
    403 Views
    A

    @Charby It works like a charm!
    Thanks you very much, I have been trying to solve this problem since hours!
    I would not have found it myself.
    Thanks again,
    Emmanuel

  • 0 Votes
    2 Posts
    280 Views
    IntruderExcluderI

    If data at that models is uniform it is better to have 1 model and change its data. Anyway, JS arrays can be used as models too, so you can have array of arrays.

  • 0 Votes
    6 Posts
    642 Views
    ArtiomA

    It really works!

    Thank you, IntruderExcluder, GrecKo.

  • 0 Votes
    4 Posts
    5k Views
    P

    @Shrinidhi-Upadhyaya Hello ,i want to remove some checked listview elements...for that can you help pls..
    Like i created a listview and gave checkbox so i want to remove the items which are checked by clicking one delete button ,some are saying i can use signal slots in cpp and connect to the qml but i really have no idea how to do that,can you please help me with that.

  • 0 Votes
    3 Posts
    614 Views
    B

    That's the solution I usually choose when encountering such a problem, but in my case there can be multiple views open at the same time, which do not need to be in sync.
    If anyone else has a suggestion how to resolve this problem I am open to suggestions.

  • 0 Votes
    2 Posts
    1k Views
    F

    @Flesh Romha Korev on stackoverflow.com gave me this answer:

    onSortIndicatorColumnChanged: tableView.model = (sortIndicatorColumn == 0) ? myListModel1 : myListModel2 onSortIndicatorOrderChanged: tableView.model = (sortIndicatorColumn == 0) ? myListModel1 : myListModel2
  • 0 Votes
    11 Posts
    1k Views
    Christian EhrlicherC

    Can we finally see where and how you emit dataChanged()? And with which indexes?

  • 2 Votes
    2 Posts
    789 Views
    K

    Waiting for guide "How to avoid JavaScript models in Qt and why should you care" (performance, memory usage)

  • 0 Votes
    2 Posts
    831 Views
    DiracsbracketD

    Hi @larkei15
    I don't think using a Repeater for dynamically changing models is the best approach.

    From the Cadaques book:
    https://qmlbook.github.io/ch06/index.html

    For static models, a Repeater can be used as the view. It is easy to combine it with a positioner such as Row, Column, Grid or Flow to build user interface parts. For dynamic or large data models, a view such as ListView or GridView are more appropriate. These create delegate instances on the fly as they are needed, reducing the number of elements live in the scene at once.

    And from the QML doc:
    http://doc.qt.io/qt-5/qml-qtquick-repeater.html

    Considerations when using Repeater
    The Repeater type creates all of its delegate items when the repeater is first created. This can be inefficient if there are a large number of delegate items and not all of the items are required to be visible at the same time. If this is the case, consider using other view types like ListView (which only creates delegate items when they are scrolled into view) or use the Dynamic Object Creation methods to create items as they are required.

    I wager your syncing problems are due to that...

    Is there any reason why you are choosing the Column + Repeater approach over the ListView approach?

  • 0 Votes
    1 Posts
    548 Views
    No one has replied
  • 0 Votes
    27 Posts
    12k Views
    O

    @GrecKo said in Binding C++ properties exposed to QML to dynamically created QML objects:

    Ultimately I think that you should use imperative object creation only for temporary object needed by the UI layer, like showing a dialog for example. I have yet to see another legit usecase for it (or I don't remember it).

    I will keep this in mind!

    Hopefully this little discusion might help someone else struggling to understand the same concepts!

  • 0 Votes
    6 Posts
    5k Views
    JLimbockerJ

    @cjmdaixi
    It was my understanding that this operation only needs to occur when the size of the model is being changed, i.e. when rows are being added to the structure. In this case, I simply want to access data members in the model. I will implement the begin/endInsertRows and see if it makes a difference.
    It is also worth mentioning that I am able to confirm that changes are being made to the C++ model. The problem seems to be that the QML is not seeing the updates. I believe a solution would be to find a way to manually update the delegates in the ListView, but there doesn't seem to be a straightforward way to do this.

  • 0 Votes
    2 Posts
    2k Views
    ekkescornerE

    you should use a Flat Button to do this

    here's an example how you can do this.

    import QtQuick 2.6 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.0 import QtQuick.Controls.Material 2.0 // Flat Button Button { id: button property alias textColor: buttonText.color focusPolicy: Qt.NoFocus Layout.fillWidth: true Layout.preferredWidth : 1 leftPadding: 6 rightPadding: 6 contentItem: Text { id: buttonText text: button.text opacity: enabled ? 1.0 : 0.3 color: Material.primaryColor horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight font.capitalization: Font.AllUppercase font.weight: Font.Medium } background: Rectangle { id: buttonBackground implicitHeight: 48 Layout.minimumWidth: 88 color: button.pressed ? buttonText.color : "transparent" radius: 2 opacity: button.pressed ? 0.12 : 1.0 } // background } // button

    feel free to modify the Button to fit into your UI
    in my blog series about Qt 5.7 QtQuickControls2 you'll find more infos: http://j.mp/qt-x

  • 0 Votes
    2 Posts
    1k Views
    M

    I wasn't able to fix the issue but I solved my problem using a ListView instead of a Column and setting the selected property as ListView.isCurrentItem in the delegate.

  • 0 Votes
    1 Posts
    526 Views
    No one has replied
  • 0 Votes
    2 Posts
    2k Views
    S

    I create MyClass and pass 4 images to QML in main.cpp

    class.h

    #ifndef MYCLASS_H #define MYCLASS_H #include <QDebug> #include <QObject> class MyClass : public QObject { Q_OBJECT Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY pathChanged); public: explicit MyClass(QObject *parent = 0); MyClass(QString path) { m_imagePath = path; } QString imagePath(); void setImagePath(const QString & path); signals: void pathChanged(QString path); private: QString m_imagePath; }; #endif // MYCLASS_H

    main.cpp

    QApplication app(argc, argv); app.setWindowIcon(QIcon("qrc:/images/logo.ico")); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QList<QObject*> dataList; dataList.append(new MyClass("/images/images/zaglowek.png")); dataList.append(new MyClass("/images/images/pilot.png")); dataList.append(new MyClass("/images/images/uklad_jezdny.png")); dataList.append(new MyClass("/images/images/nozne_sterowanie.png")); engine.rootContext()->setContextProperty("myModel", QVariant::fromValue(dataList));

    For Now MyClass has only image path, but it will also set state (checked-unchecked) and animation (enable-disable).
    I would like to reload this QList ( with another images, states etc. ) when button ( one of three ) is clicked ( TButton.qml ).
    How to do it ? Please help.

  • 0 Votes
    5 Posts
    4k Views
    S

    Hmmm...okay, I think it works now.

    I will create "backup.qml" dynamically with Qt.createComponent() and createObject(root, {listModel: ListModel}).

    After that I access the property listModel in the created component, iterate over the current listModel which should be backuped and append that items in the listModel of the new-created component.

    At the end I push the new-created component on stack to be able to backup more than one "state" of the model.

  • 0 Votes
    2 Posts
    925 Views
    SGaistS

    Hi and welcome to devnet,

    If you would like to have more information, please post a comment on the bug report. Since it's done it means that the problem has been fixed but you will have to either wait for 5.5.1 or build Qt3D yourself.