【问题标题】:QTableView animate row hidingQTableView 动画行隐藏
【发布时间】:2017-07-23 11:59:49
【问题描述】:

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

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

【问题讨论】:

    标签: c++ qt qtableview


    【解决方案1】:

    您可能可以通过使用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);
    

    请注意,以上代码未经测试。此外,与其创建一个“空灵”QTimer,不如将​​其设为视图类的成员变量或其他任何东西。

    【讨论】:

    • 我有同样的想法,但我认为可能有一些更方便的方法。我将对此进行测试并报告。谢谢
    • 它有效。虽然整个事情看起来像一个黑客。我想使用合适的动画框架,但是……就是这样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    • 2011-03-16
    • 2013-09-30
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多