Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved TableView Snap to Row Feature / Implementation

    QML and Qt Quick
    1
    2
    76
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rhb327 last edited by

      I'm using the newer TableView:

      import QtQuick 2.12
      import Qt.labs.qmlmodels 1.0
      import QtQuick.Controls 2.12

      I'm curious if I can enable something like the GridView snapToRow setting with a TableView. Each of my rows could have a custom height so a simple modulo based calculation will not work.

      Thanks,
      -Rich

      1 Reply Last reply Reply Quote 0
      • R
        rhb327 last edited by rhb327

        As I have a "white" space between the rows here's one possible implementation:

        This is in a custom model:

         Q_INVOKABLE int alignRow(QObject* obj) {
             QQuickItemGrabResult *item = qobject_cast<QQuickItemGrabResult*>(obj);
             QImage qi(item->image());
             int cnt = 0;
             while (cnt <= 130) {
                 if(QColor(qi.pixelColor(1,1+cnt*2)).name() == "#000000") {
                     break;
                 }
                 ++cnt;
             }
             return (cnt==200) ? 0 : 1+cnt*2;
         }
        
        

        With this on the QML side from a TableView:

        onMovementEnded: {
                    eventLogView.grabToImage(function(result) { var shift = sqlELmodel.alignRow(result);
                        eventLogView.contentY += shift;
                    })
                }
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post