QScrollArea autoscroll on children drag



  • Hello everyone, my first post :)

    I have encountered a problem with something I am trying to achieve.

    I have a QScrollArea, that contains widgets in a vertical layout.

    I have implemented a drag&drop system that lets me drag the widgets, allowing me to swap the order of them inside the QScrollArea.

    I can dynamically add more widgets to the QScrollArea, so over time - the scroll area can end up quite large.

    For a convenience feature, I'd like to be able to scroll the QScrollArea whilst I'm in a drag process, based on where the mouse position is inside the QScrollArea.

    I have the right logic to do this, as I have tested it outside the context of dragging.

    My problem is, is that the QDrag.start() method blocks the program from any further calculation until the drag is finished. So I can't use a dragMoveEvent() oe mouseMoveEvent() on the QScrollArea to update it's scroll position.

    Can anyone think of a way to achieve this?

    Thanks!


  • Qt Champions 2016

    Hi and welcome

    Hmm for Start()
    http://doc.qt.io/qt-5/qdrag-obsolete.html
    Docs says
    "Note: Although the drag and drop operation can take some time, this function does not block the event loop. Other events are still delivered to the application while the operation is performed."

    However for
    http://doc.qt.io/qt-5/qdrag.html#exec
    it says " On Windows, the Qt event loop is blocked during the operation. However, QDrag::exec() on Windows causes processEvents() to be called frequently to keep the GUI responsive. If any loops or operations are called while a drag operation is active, it will block the drag operation."

    So it should not block ? But it sounds like your experience is that it does?



  • Actually yes, that is half correct it seems.

    It appears that dragEnterEvent event is working whilst the QDrag is active, but not the dragMoveEvent.

    I'm using qt 4 and this tool is for Autodesk Maya if that makes and difference?


  • Qt Champions 2016

    Hmm
    We kinda need dragMoveEvent to be active to do some scrolling. This is not a uncommon
    use case so others might have a good idea besides using dragMoveEvent.

    • I'm using qt 4 and this tool is for Autodesk Maya if that makes and difference?
      I think not as it seems to be same doc for Qt4.

    So platform is Windows?



  • I would like this to work across Windows and Linux :)


  • Lifetime Qt Champion

    Hi,

    How are you implementing your dragEnter event ?



  • Hi SGaist,

    I am creating a new class inheriting the QScrollArea object.

    There are widgets inside it with mouseMoveEvents() that instigate a QDrag event.

    I have tried putting various mouse events in the new inherited class like the dragEnter event. The dragEnter event actually appears to work. But its the dragMoveEvent that I'm having trouble with! :(


  • Qt Champions 2016

    Seems that QScrollArea is different from others widgets in that regards
    as it seems the views can do it.
    ( scrolling during drag operation )



  • @mrjj I've just tried scrolling this way on my QScrollArea but it's not doing the same thing. Isn't the widget you're demonstrating a QListWidget?


  • Qt Champions 2016

    @DjMonkey
    Yes, as i write "as it seems the views can do it."
    Meaning List/Tree/xxx - Views.
    Which means (seems that) that the default drag&drop do not block
    the dragMoveEvent or have some other way to make this work.
    So you could take a look in their source code to see how they do it. :)



  • @mrjj ah my apologies! I understand now :)

    I'll try to get to the bottom of this then, thanks


  • Qt Champions 2016

    @DjMonkey
    Oh no need for apologies, it was not really clear from my post :)
    Well please do post back if you find out.

    Also if you have some test code, ill be happy to play with it.



  • @mrjj I have figured out a solution!

    It seems to work by moving the dragMoveEvent onto the child widget instead of the QScrollArea that is holding them. If I implement my logic into that and use a pointer to the QSrollArea to change its scroll bar position - that works :)


  • Qt Champions 2016

    @DjMonkey
    Super. That would work. Hopefully there are no side effects :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.