hideRow()
使行立即消失,我想要平滑过渡,一些淡入淡出效果。
这可能吗?我在文档中找不到任何参考。
答案 0 :(得分:1)
您可以使用QTableView::setRowHeight
和QTimer
。
/*
* 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);
请注意,上述代码未经测试。此外,您可能希望将其视为视图类或其他任何内容的成员变量,而不是创建“空灵”QTimer
。