[Solved] QTableWidget vertical scroll bars drag handle up & down motion is backwards ?
-
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
-
Hi,
Can you share a minimal compilable sample code that shows what happens ?
-
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
-
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);
}
@ -
You're welcome !
Thanks for sharing your setup code :)
-
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? -
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.
-
What are you getting ?