Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TableView Snap to Row Feature / Implementation

TableView Snap to Row Feature / Implementation

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 191 Views
  • 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 Offline
    R Offline
    rhb327
    wrote on 28 Jul 2021, 14:50 last edited by
    #1

    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
    0
    • R Offline
      R Offline
      rhb327
      wrote on 28 Jul 2021, 23:53 last edited by rhb327
      #2

      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
      0

      1/2

      28 Jul 2021, 14:50

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved