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. [Solved] QTableWidget vertical scroll bars drag handle up & down motion is backwards ?
QtWS25 Last Chance

[Solved] QTableWidget vertical scroll bars drag handle up & down motion is backwards ?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 5.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.
  • E Offline
    E Offline
    EdOfTheMountain
    wrote on 26 Jan 2015, 16:54 last edited by
    #1

    When using the Windows notepad app, for example, you drag the handle up to scroll-up, and down to scroll-down.

    I have a QTableWidget that under Windows is controlled by opposite mouse-drag movements?

    • The mouse scroll wheel scrolls vertical handle up and down as expected.
    • I must use opposite mouse motion to drag scroll handle up and down.
    • I cannot drag handle down when handle is at top already. I have to drag it up to move it down?

    My app has backwards mouse-drag-handle scrolling under both Windows, and OSX.

    Thanks in advance for any suggestions,

    -Ed

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 27 Jan 2015, 22:31 last edited by
      #2

      Hi,

      Can you share a minimal compilable sample code that shows what happens ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EdOfTheMountain
        wrote on 29 Jan 2015, 21:10 last edited by
        #3

        Thank you very much for taking the time to make me think.

        I ran a Qt table example and vertical scroll drag worked normally.

        My problem was I had conditional code to enable kinetic scrolling that set QScrollerProperties to make it work more native-like on Android and iOS.

        Since my MacBook has a touchpad it was considered a touch device since 1 <= QTouchDevice::maximumTouchPoints(). Since I was running Windows in a VM Fusion VM I think the touch hardware was detected in the VM as well.

        My fix was to skip this if not Android or iOS and the scroll behavior is back to normal.

        Sorry, I should have thought about making a minimal test case.

        Thank you very much for your time!

        -Ed

        1 Reply Last reply
        0
        • E Offline
          E Offline
          EdOfTheMountain
          wrote on 29 Jan 2015, 21:13 last edited by
          #4

          In case others are working on iOS and Android widget apps, this is what I am using:

          I pass my scroll area:
          @
          setupKineticScrolling(ui->scrollArea);
          @

          @
          /// Enables kinetic swipe or flick scrolling on touch devices
          /// param[in] scrollArea the QScrollArea or object derived from, for example,
          /// QTableWidget.
          ///
          /// QAbstractItemView::ScrollPerPixel
          /// ---------------------------------
          /// For a QTableWidget it is recommended to also set QAbstractItemView::ScrollPerPixel
          /// to enable smooth scrolling compared to ScrollPerItem
          ///
          /// Example:
          /// \code
          /// tableView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
          /// tableView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
          /// \endcode
          void TouchWidget::setupKineticScrolling(QObject *scrollArea)
          {
          QAbstractItemView abstractItemView = qobject_cast<QAbstractItemView>(scrollArea);
          if(0 != abstractItemView)
          {
          if(cms::crossplatform::isTouchDevice() && cms::crossplatform::isMobileDevice())
          {
          // QAbstractItemView::ScrollPerPixel results in smooth scrolling compared to ScrollPerItem
          abstractItemView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
          abstractItemView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
          }
          }

          QAbstractScrollArea *abstractScrollArea = qobject_cast<QAbstractScrollArea*>(scrollArea);
          if(0 != abstractScrollArea)
          {
              Qt::ScrollBarPolicy scrollBarPolicy = Qt::ScrollBarAsNeeded;
              if(cms::crossplatform::isTouchDevice() && cms::crossplatform::isMobileDevice())
              {
                  scrollBarPolicy =  Qt::ScrollBarAlwaysOff;
              }
              abstractScrollArea->setHorizontalScrollBarPolicy(scrollBarPolicy);
              abstractScrollArea->setVerticalScrollBarPolicy(scrollBarPolicy);
          }
          
          if(false == cms::crossplatform::isMobileDevice())
          {
              return;
          }
          
          // Something in this section made the vertical scroll bar handle-drag control work backwards
          // on desktop OS X and Windows.
          // Execute this section for Android or iOS only.
          QScroller::grabGesture(scrollArea,
                                 QScroller::LeftMouseButtonGesture);
          
          
          // Adjust OvershootPolicy so it does not look wobbly, like table not attached to widget
          QScrollerProperties properties = QScroller::scroller(scrollArea)->scrollerProperties();
          QVariant overshootPolicy =
                  QVariant::fromValue<QScrollerProperties::OvershootPolicy>
                  (QScrollerProperties::OvershootAlwaysOff);
          properties.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy,
                                     overshootPolicy);
          properties.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy,
                                     overshootPolicy);
          QScroller::scroller(scrollArea)->setScrollerProperties(properties);
          

          }
          @

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 30 Jan 2015, 00:19 last edited by
            #5

            You're welcome !

            Thanks for sharing your setup code :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • T Offline
              T Offline
              trstalker
              wrote on 8 Jun 2015, 17:37 last edited by trstalker 6 Aug 2015, 18:25
              #6

              Hello! I put this code to my program, but i it crash in start. What am i doing wrong?
              ...
              QScrollArea* scrollFullSolution = new QScrollArea;
              QAbstractItemView* view = qobject_cast<QAbstractItemView*>(scrollFullSolution);
              view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
              view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
              ...
              Debugger show, that view is always NULL pointer. Why?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 8 Jun 2015, 20:50 last edited by
                #7

                Hi and welcome to devnet,

                scrollFullSolution is a pointer to a QScrollArea not a QAbstractItemView that's why qobject_cast returns 0.

                PS: next time please start a new thread for your problem rather than highjack someone else's.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • T Offline
                  T Offline
                  trstalker
                  wrote on 9 Jun 2015, 05:51 last edited by
                  #8

                  SGaist, thanks for answer! How can i use these two methods for my QScrollArea? I fully repeat the EdOfTheMountain's code, but it does not give positive result...

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 9 Jun 2015, 21:52 last edited by
                    #9

                    What are you getting ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      trstalker
                      wrote on 10 Jun 2015, 05:58 last edited by
                      #10

                      I found a solution for this problem. I used QScrollArea::horizontal(vertical)ScrollBar::setSingleStep(1). Now scroll smoothly and quickly :)

                      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