Important: Please read the Qt Code of Conduct -

Scrolling the list while mouse is pressed in delegate

  • Hi everyone.

    I need to scroll the list when mouse is pressed and at the bottom or top of the list until mouse is released.
    I tried to use timer, which is scrolling the list while mouse cursor is in position of bottom or top of listView.
    When item of the list is out of screen, all mouse actions of delegate that is out of screen no longer available, and timer doesn't stop when i release the mouse button;
    So, i decided to use mouseArea that is child of listView, but every time i need to get items properties, i have to set currentIndex to ListView, and than use currentItem to get properties.
    It works fine, but i am not sure if it is the best way in such situation.

    I also was trying to make my own mouseArea by reimplementing the QDeclarativeItem, where event will be accepted only when mouse button is released, and when it is pressed event will be ignore.
    But unfurtunaly i failed, because if event->ignore() is set in MousePressEvent(), MouseReleaseEvent() is no longer working.
    Is there any possibility to make that what i want?


  • I am not quite sure what you are trying to say, so I hope I do not misunderstand the issue.

    You should not ignore the mouse press event when you need the release event, because the release event will only occur if there was a press event beforehand. You could of course set a flag to prevent execution of code, but I think your problem can be solved otherwise.

    1. Have you already tried to achieve what you want with a Flickable element? If need be, you could build your own element and just parse your click events to the Flickable's movement events.
    2. Another way, pretty fancy, would be to use a simple rectangle that changes its position based on the clicks, i.e. you could implement the scrolling feature by hand.

    Concerning the ListView index issue, I think there is no better solution. I have also had my fights with it, so if there really is a better way, I would also like to know it.

    Hope that was of any help to you.

  • I'm not sure if I understood what you want to achieve. But I guess it could be the behaviour of the "QAbstractItemView autoScroll property":

Log in to reply