QT4:是否可以使 QListView 平滑滚动? [英] QT4: Is it possible to make a QListView scroll smoothly?

查看:88
本文介绍了QT4:是否可以使 QListView 平滑滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在图标模式下有一个 QListView 有很多图标,所以会出现一个滚动条,但滚动不流畅,恕我直言,这让用户感到困惑,因为它在每次滚动时突然从一个点跳到另一个点.我想让滚动平滑,但我在文档中没有找到任何内容.可能吗?

I have a QListView in Icon mode with lots of icons, so that a scrollbar appears, but the scrolling is not smooth and this IMHO confuses the user since it jumps abruptly from one point to another at each scroll. I would like to make the scrolling smooth but I didn't find anything in the docs. Is it possible?

推荐答案

如果我正确理解您的问题,您希望重新定义小部件的滚动行为.我想会发生什么是当用户点击滚动箭头(在下图中标记为 b )时,列表视图会按项目的高度滚动.

If I understand your question correctly you would like to redefine the scrolling behavior of the widget. I guess what happens is that listview is getting scrolled by the item's height whenever users hits a scroll arrow (marked as b on the image below).

对于连接到列表视图的垂直滚动条,滚动箭头通常将当前位置向上或向下移动一个行",并少量调整滑块的位置.我相信在这种情况下,线是图标的高度.您可以通过安装和 item delegate (setItemDelegate) 并覆盖其 sizeHint 方法.虽然这不会帮助你解决这个问题.您可以尝试创建一个 QListView 后代并覆盖其 updateGeometries 方法.在那里你可以将垂直滚动条设置为你想要的值,我猜这个任务是 1 或 2.以下是自定义列表视图的示例:

For a vertical scroll bar connected to a list view, scroll arrows typically move the current position one "line" up or down, and adjust the position of the slider by a small amount. I believe line in this case it is an icon's height. You can adjust items height by installing and item delegate (setItemDelegate) and overriding its sizeHint method. Though this would not help you to solve this problem. What you could try is to create a QListView descendant and override its updateGeometries method. There you can setup the vertical scrollbar step to the value you want, I guess 1 or 2 for this task. Below is an example of the custom listview:

class TestListView : public QListView
{
Q_OBJECT
public:
    explicit TestListView(QWidget *parent = 0);

protected:
    virtual void updateGeometries();
};

TestListView::TestListView(QWidget *parent) :
    QListView(parent)
{
    //???
}

void TestListView::updateGeometries()
{
    QListView::updateGeometries();
    verticalScrollBar()->setSingleStep(2);
}

希望对您有所帮助,问候

hope this helps, regards

这篇关于QT4:是否可以使 QListView 平滑滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆