Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MItemViewSet BigViewType的刷新问题 #42

Open
reinalin opened this issue Jul 5, 2022 · 4 comments
Open

MItemViewSet BigViewType的刷新问题 #42

reinalin opened this issue Jul 5, 2022 · 4 comments

Comments

@reinalin
Copy link

reinalin commented Jul 5, 2022

使用MItemViewSet BigViewType时,当数量多时(100以上),改变窗口大小会有明显的卡顿问题,是因为改变大小都会多次重新设置model里的data吗?
操作录屏

@muyr
Copy link
Contributor

muyr commented Jul 19, 2022

经测试,是 QListView.setResizeMode(QtWidgets.QListView.Adjust) 的锅,每次窗口大小修改,需要重新计算布局(每行多少个)

@muyr
Copy link
Contributor

muyr commented Jul 19, 2022

https://code.qt.io/cgit/qt/qtbase.git/plain/src/widgets/itemviews/qlistview.cpp
源码里面已经做了延迟(0.1秒) layout 处理了,所以我们在放大窗口的时候,可以明显看到一个白色背景(我们ListView是个深色背景,没有立马跟着变大),所以,要么我们加大延迟,则白边效果会更显著;要么我们就搞分页;

void QListView::resizeEvent(QResizeEvent *e)
{
    Q_D(QListView);
    if (d->delayedPendingLayout)
        return;

    QSize delta = e->size() - e->oldSize();

    if (delta.isNull())
      return;

    bool listWrap = (d->viewMode == ListMode) && d->wrapItemText;
    bool flowDimensionChanged = (d->flow == LeftToRight && delta.width() != 0)
                                || (d->flow == TopToBottom && delta.height() != 0);

    // We post a delayed relayout in the following cases :
    // - we're wrapping
    // - the state is NoState, we're adjusting and the size has changed in the flowing direction
    if (listWrap
        || (state() == NoState && d->resizeMode == Adjust && flowDimensionChanged)) {
        d->doDelayedItemsLayout(100); // wait 1/10 sec before starting the layout
    } else {
        QAbstractItemView::resizeEvent(e);
    }
}

@reinalin
Copy link
Author

reinalin commented Jul 19, 2022

之前我用原生listview的时候用的方法是直接在listveiw的resizeEvent中用listview的setSpacing和setGridSize效果倒是不会出现卡的现象,下面这个视频里面也是100多个的图标
视频

@muyr
Copy link
Contributor

muyr commented Jul 19, 2022

确实一个人精力有限,只能考虑一般情况。
非常欢迎你贡献代码,这里有 如何贡献代码 的步骤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants