Files
StarPilot/selfdrive/ui/qt/widgets/scrollview.cc
T
iejMac 9238fade18 scrolling in text window (#20564)
* grid layout  + better scrollbar

* style

* style

* tabs

* scrollbar behind button fix

* alerts background color fix (#20568)

* horizontal style + more space for scrollbar

* fixes

* fixes

* fixes

* remove background on scroll bar

* fix horizontal overflow

* indent'

Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 10e4d321977928a7314cd4149ba29ea08798820a
2021-04-03 01:18:26 -07:00

43 lines
1.4 KiB
C++

#include <QScrollBar>
#include "scrollview.hpp"
ScrollView::ScrollView(QWidget *w, QWidget *parent) : QScrollArea(parent){
setWidget(w);
setWidgetResizable(true);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setStyleSheet("ScrollView { background-color:transparent; }");
QString style = R"(
QScrollBar:vertical {
border: none;
background: transparent;
width:10px;
margin: 0;
}
QScrollBar::handle:vertical {
min-height: 0px;
border-radius: 4px;
background-color: white;
}
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {
height: 0px;
}
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
background: none;
}
)";
verticalScrollBar()->setStyleSheet(style);
horizontalScrollBar()->setStyleSheet(style);
QScroller *scroller = QScroller::scroller(this->viewport());
QScrollerProperties sp = scroller->scrollerProperties();
sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff));
sp.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff));
scroller->grabGesture(this->viewport(), QScroller::LeftMouseButtonGesture);
scroller->setScrollerProperties(sp);
}