Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
Scrolling top bar
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Oct 15, 2016
1 parent 3eaadba commit 51f69e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 16 additions & 3 deletions mousescrollwidget.cpp
Expand Up @@ -35,9 +35,15 @@ void MouseScrollWidget::mouseMoveEvent(QMouseEvent *event) {
}
}

void MouseScrollWidget::wheelEvent(QWheelEvent *event) {
//this->scroll(event->delta(), 0);
if (event->orientation() == Qt::Vertical) {
this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() - event->delta());
}
}

void MouseScrollWidget::setWidget(QWidget *widget) {
QScrollArea::setWidget(widget);

}

void MouseScrollWidget::setEventFilter(QWidget *widget) {
Expand Down Expand Up @@ -112,10 +118,17 @@ bool MouseScrollWidget::eventFilter(QObject *object, QEvent *event) {
} else if (event->type() == QEvent::Leave) {
shiftLeft.stop();
shiftRight.stop();
} else if (event->type() == QEvent::Scroll) {
/*} else if (event->type() == QEvent::Scroll) {
QScrollEvent* scrollEvent = (QScrollEvent*) event;
this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() + scrollEvent->contentPos().y());
this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() + scrollEvent->contentPos().y());*/
/*} else if (event->type() == QEvent::Wheel) {
QWheelEvent* wheelEvent = (QWheelEvent*) event;
//this->scroll(wheelEvent->delta(), 0);
if (wheelEvent->orientation() == Qt::Vertical) {
this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() + wheelEvent->delta() / 8 / 15);
}*/
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions mousescrollwidget.h
Expand Up @@ -3,6 +3,7 @@

#include <QScrollArea>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QTimer>
#include <QApplication>
#include <QStyle>
Expand All @@ -25,6 +26,7 @@ public slots:
private:
QTimer shiftLeft, shiftRight;
void mouseMoveEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
bool eventFilter(QObject *object, QEvent *event);

void setEventFilter(QWidget* widget);
Expand Down

0 comments on commit 51f69e9

Please sign in to comment.