QTableView动画行隐藏

QTableView animate row hiding

hideRow() 使行立即消失,我想要平滑过渡,一些淡入淡出的效果。

这可能吗?我在文档中找不到任何参考资料。

您可能可以使用 QTableView::setRowHeightQTimer

/*
 * Get QTableView pointer and index of the row to hide from
 * somewhere.
 */
QTableView *tv = ...;
int row = ...;

/*
 * Create a timer.  It will be deleted by our lambda when no
 * longer needed so no memory leak.
 */
auto *timer = new QTimer;

/*
 * Connect the timer's timeout signal to a lambda that will
 * do the work.
 */
connect(timer, &QTimer::timeout,
        [=]()
        {
          int height = tv->rowHeight(row);
          if (height == 0) {

            /*
             * If the row height is already zero then hide the
             * row and delete the timer.
             */
            tv->setRowHidden(row, true);
            timer->deleteLater();
          } else {

            /*
             * Otherwise, decrease the height of the row by a
             * suitable amount -- 1 pixel in this case.
             */
            tv->setRowHeight(row, height - 1);
          }
        });

/*
 * Start the timer running at 10Hz.
 */
timer->start(100);

请注意,以上代码未经测试。此外,与其创建 'ethereal' QTimer,不如将其作为视图的成员变量 class 或其他任何内容。