For the record, then. If you reimplement the scrollContentsBy() function of QAbstractScrollArea, you will receive the delta values from both scroll bars at once, without having to declare slots or install event filters.
void MyCustomView::scrollContentsBy(int dx, int dy)
{
// dx = horizontal delta
// dy = vertical delta
}
void MyCustomView::scrollContentsBy(int dx, int dy)
{
// dx = horizontal delta
// dy = vertical delta
}
To copy to clipboard, switch view to plain text mode
Btw, installing an event filter:
{
horizontalScrollBar()->installEventFilter(this);
verticalScrollBar()->installEventFilter(this);
}
{
bool vbar = (object == verticalScrollBar();
bool hbar = (object == horizontalScrollBar();
if (!vbar && !hbar)
return false;
switch (event) {
case MouseButtonPress:
if (vbar) { /* someone pressed the vertical bar */ }
else { /* someone pressed the horizontal bar */ }
break;
case MouseButtonPress:
if (vbar) { /* someone released the vertical bar */ }
else { /* someone released the horizontal bar */ }
break;
case MouseMove:
if (vbar) { /* someone pressed and moved the vertical bar */ }
else { /* someone pressed and moved the vertical bar */ }
break;
...
default:
break;
}
}
MyCustomView::MyCustomView(QGraphicsScene *scene, QObject *parent)
: QGraphicsView(scene, parent)
{
horizontalScrollBar()->installEventFilter(this);
verticalScrollBar()->installEventFilter(this);
}
bool MyCustomView::eventFilter(QObject *watched, QEvent *event)
{
bool vbar = (object == verticalScrollBar();
bool hbar = (object == horizontalScrollBar();
if (!vbar && !hbar)
return false;
switch (event) {
case MouseButtonPress:
if (vbar) { /* someone pressed the vertical bar */ }
else { /* someone pressed the horizontal bar */ }
break;
case MouseButtonPress:
if (vbar) { /* someone released the vertical bar */ }
else { /* someone released the horizontal bar */ }
break;
case MouseMove:
if (vbar) { /* someone pressed and moved the vertical bar */ }
else { /* someone pressed and moved the vertical bar */ }
break;
...
default:
break;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks