Skip to content
  • 0 Votes
    3 Posts
    254 Views
    S0ulM1keS

    @GrecKo the problem is, that GridView releases it delegates when model's elements is removed. It provokes Image to reload if delegate is shown again. No meter if I set cache: true

    Such a shame that GridView don't have reuseItems like ListView

    I've come with next decision. I've created Repeater containing Image that use source model. GridView's delegate Image use Repeater's function itemAt() giving delegate's index after mapping to source model:

    //Image in deleagte Image { Component.onCompleted: { source = appModelImages.loadImage(appFilterModel.mapRowToSource(parent.delegateIndex)) // custom implementation } ... } //Repeater Repeater { id: appModelImages visible: false function loadImage(index){ return itemAt(index).source } model: AppModel delegate: Image { visible: false asynchronous: true source: model.boxart } }

    This may be not the best decision, but "faster" than create own delegate pool for GridView. Didn't see any examples of implementing mechanism like this. Repeater should work fine, as it relays on source model. And as I expected, images live when source model does.

  • 0 Votes
    1 Posts
    117 Views
    No one has replied
  • 0 Votes
    1 Posts
    199 Views
    No one has replied
  • 0 Votes
    5 Posts
    1k Views
    N

    Hi @LeLev,

    I tried your solution. Its showing the image. That is fine.
    Now if i have more elements then its filling in the same space.
    I need to scroll thorough the screen to see the elements.
    How to do that ? How should I use Flickable in this case.

    Note: For example: If the screen layout is 500x500, and each element size id 50x50,
    then i should only see 16 elements initially. I have to scroll down on the screen to see the remaining elements.

  • 0 Votes
    1 Posts
    443 Views
    No one has replied
  • 0 Votes
    9 Posts
    873 Views
    J.HilkJ

    @Slash200

    Gibt es in QML eine View die das freie einfügen von Items in eine Zelle ermöglicht, ohne dass die vorherigen Zellen ein Item haben?

    Nein, nicht das ich es kennen würde. Da musst du dir was eigenes Schreiben, was sich die Postion von allem Items merkt und ach entsprechend neu positioniert, wenn sich die Fenstergröße ändert zum Beispiel.

    Übrigens, hab das Beispiel erweitert über den "Add" Knopf kann man jetzt eines der freien "Dummy"-Elemente ersetzen

    Hattest du dir das so gedacht?

  • 0 Votes
    2 Posts
    938 Views
    AdrianJadeA

    I finally found the answer in my problem:

    FolderListModel {
    ...
    sortReversed: true
    }

  • 0 Votes
    4 Posts
    10k Views
    L

    First of all I am glad that you found a solution you're happy with.
    Nevertheless, I still recommend to use GridView. On the one hand, it probably reduces your amount of code, on the other hand, and most importantly, it's much more readable to you and every other developer, who might want to help you or needs some Inspiration, because he has the same problems as you have.

    To your question:

    On of the key features of Qml is property binding. So let's say you have

    import QtQuick.Controls 2.3 ApplicationWindow { id: root width: 600; height: 600 visible: true Rectangle { width: parent.width/2; height: parent.height/2 color: "blue" } MouseArea { anchors.fill: parent onClicked: { root.width -= 10; root.height += 10; } } }

    If you click the applicationWindow its width will be decreased by 10 and its height increased by 10. At the same time the rectangle's width will be decreased by 5 and its height increased by 5. That's because its size depends on the size of the applicationWindow and will be changed automatically.

    Same applies to your case. If the model changes its size, your ListView should notice this and update the list.

    Just in case you don't know (or if it's working in your case, didn't know how your model looks like) you can do:
    model: yourModelName.length
    or if it's a List of Arrays/Vectors
    model: yourModelName[index].length

    Index should be available through the outer ListView if I did understand you correctly.

    ListView { model: yourModel.length delegate: ListView { model: yourModel[index].length } }

    Probably there is no need to write an "getLengthOfDataVector" function, if you intended to do it like this. But maybe I missed something as I don't know how you model looks like exactly.

  • 0 Votes
    3 Posts
    1k Views
    ekkescornerE

    @VRonin yes - it's a list of QObject*
    each entry describes a File:

    Folder, File Type (Image, Video, PDF, ...) Path Name (obsolet for iOS Photos) entries (if Folder) ...
    and I'm constructing the collection per ex. from PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
  • 0 Votes
    3 Posts
    1k Views
    M

    Ok thx, i've also found a very detailed solution on stackoverflow on how to use a parent above evrything to display a component on top.
    I didn't know about the ToolTip component. i might endup using it since it has the same purpose as what I did but probably more efficient and more weird-case-proof. So thank you for your answser.

  • 0 Votes
    2 Posts
    2k Views
    sierdzioS

    Please do not double-post. I'm closing this one.

  • 0 Votes
    1 Posts
    889 Views
    No one has replied
  • Problem with GridView

    Unsolved QML and Qt Quick
    4
    0 Votes
    4 Posts
    1k Views
    p3c0P

    @lorow23

    but how I should acces particular rectangles then?

    With the model approach it wont be required. The delegate items will get the data from model. Also when required you just need to update the model with new data from the delegate or from outside.
    For eg. ListModel has several methods to access the data.

  • 0 Votes
    2 Posts
    2k Views
    p3c0P

    @Mark81
    The cellHeight when changes updates the cellWidth in this line:

    cellWidth: Math.min(parent.width, parent.height) == parent.width ? parent.width / 3 : cellHeight

    this cellWidth change re-evaluates the binding and updates the cellHeight in this line:

    cellHeight: Math.min(parent.width, parent.height) == parent.width ? cellWidth : parent.height / 2

    And this goes on foreever and hence the error.

    By the way, how to center the GridView content? It fills the available space from left-to right.

    How do you want it to appear ? Can you share some image ?

  • 0 Votes
    2 Posts
    1k Views
    L

    Doing calculations is the best way. Please, see:

    https://forum.qt.io/topic/64977/alignment-questions-for-qml-gridview

  • 0 Votes
    3 Posts
    1k Views
    C

    @clarity The Gridview is not a table. It's a list that wraps around

  • 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
    1 Posts
    657 Views
    No one has replied
  • 0 Votes
    2 Posts
    916 Views
    E

    I figured out why the GridView wasn't scrolling. I'm still having issues with the transitions as I described, but I don't think that's really a reasonable question to ask here at this time...so that's why I deleted the post.