TableView Snap to Row Feature / Implementation
Unsolved
QML and Qt Quick
-
I'm using the newer TableView:
import QtQuick 2.12
import Qt.labs.qmlmodels 1.0
import QtQuick.Controls 2.12I'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 -
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; }) }