Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Srolling through QListView items without any mouse move event!

Srolling through QListView items without any mouse move event!

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stoned Jesus
    wrote on last edited by
    #1

    I have a QListView which contains QStandardItems. When I drag an item on one of the QStandardItems (first or last which is currently visible to the user), the scroll bar should move backward/forward making the items scroll without any mouse move event. I mean when a place the cursor on first or last item visible, the items should be scrolled.

    --
    Thanks & Regards,
    Stoned Jesus

    1 Reply Last reply
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      you should use QListView::verticalScrollBar->setValue(currentValue + heightOfQStandardItem);

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        use this code in your derived class' QAbstractItemView::viewportEvent() ... or use an eventFilter on the viewport if you don't want to subclass:
        @
        void MyView::viewportEvent ( QEvent * event )
        {
        if( event->type() == QEvent::DragMove )
        {
        QModelIndex index = view->indexAt(event->pos());
        if( index.isValid() )
        {
        QRect visualRect = view->visualRect(index);
        QRect viewportRect = view->viewport()->rect();
        if( (viewportRect | visualRect) != viewportRect ) //index is currently not completely visible
        view->scrollTo(index);
        }
        }
        QListView::viewportEvent(event);
        }
        @

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • 8 Offline
          8 Offline
          8majkel8
          wrote on last edited by
          #4

          List view does it by default. If you drag an element and stop over last one (or edge of viewport) list view will start scrolling after less than a second.
          When you subclass some class and reimplement virtual methods you actually lost it's previous functionality. Especially when you sublcass widgets you somehow break it's inner state. It is important to call parent method from within your class to get it back.

          This example works for me.

          @
          void CustomListView::dragEnterEvent(QDragEnterEvent * event)
          {
          if (event is mine) {
          event->acceptProposedAction();
          }
          else QListView::dragEnterEvent(event);
          }

          void CustomListView::dropEvent(QDropEvent * event)
          {
          if (event is mine) {
          event->acceptProposedAction();
          }
          else QListView::dropEvent(event);
          }

          void CustomListView::dragMoveEvent(QDragMoveEvent * event)
          {
          QListView::dragMoveEvent(event);
          if (event is mine) {
          event->acceptProposedAction();
          }
          }

          void CustomListView::mousePressEvent(QMouseEvent * event)
          {
          if (event->button() == Qt::LeftButton)
          _dragPos = event->pos();
          QListView::mousePressEvent(event);
          }

          void QDropBoxListView::mouseMoveEvent(QMouseEvent * event)
          {
          if (event->buttons() & Qt::LeftButton) {
          if ((event->pos() - _dragPos).manhattanLength()
          >= QApplication::startDragDistance()) {
          //start my custom drag
          }
          }
          QListView::mouseMoveEvent(event);
          }
          @

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Stoned Jesus
            wrote on last edited by
            #5

            Thanks a lot!!! It worked...

            [quote author="raven-worx" date="1371017854"]use this code in your derived class' QAbstractItemView::viewportEvent() ... or use an eventFilter on the viewport if you don't want to subclass: @ void MyView::viewportEvent ( QEvent * event ) { if( event->type() == QEvent::DragMove ) { QModelIndex index = view->indexAt(event->pos()); if( index.isValid() ) { QRect visualRect = view->visualRect(index); QRect viewportRect = view->viewport()->rect(); if( (viewportRect | visualRect) != viewportRect ) //index is currently not completely visible view->scrollTo(index); } } QListView::viewportEvent(event); } @[/quote]

            --
            Thanks & Regards,
            Stoned Jesus

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved